Android根检查器,Java问题
在我的应用程序开始时,我正在制作一个简单的根检查器,如果您安装了SuperSU,它可以正常工作,但它不适用于其他根管理器,如KingRoot等 我需要它为任何根管理器工作 我看不出问题,因为它只是将文件作为根进程写入,然后检查退出代码。。所以假设它对任何一个经理都有效,但它不 请帮帮我。。。我正在使用的代码Android根检查器,Java问题,java,android,android-fragments,android-activity,Java,Android,Android Fragments,Android Activity,在我的应用程序开始时,我正在制作一个简单的根检查器,如果您安装了SuperSU,它可以正常工作,但它不适用于其他根管理器,如KingRoot等 我需要它为任何根管理器工作 我看不出问题,因为它只是将文件作为根进程写入,然后检查退出代码。。所以假设它对任何一个经理都有效,但它不 请帮帮我。。。我正在使用的代码 try { Process p = Runtime.getRuntime().exec("su"); DataOutpu
try
{
Process p = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("echo \"TEST\" > /system/temp.txt\n");
os.writeBytes("exit\n");
os.flush();
try
{
p.waitFor();
if (p.exitValue() == 1)
{
}
else if (p.exitValue() == 0)
{
AlertDialog.Builder alertDial = new AlertDialog.Builder(this);
alertDial.setCancelable(false);
alertDial.setTitle("PRE-ROOT CHECK");
alertDial.setMessage("You don't have root access ! \nThis is a not going to work !");
alertDial.setPositiveButton(" Exit ", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which)
{
System.exit(0);
}
});
alertDial.setIcon(R.drawable.ic_launcher);
alertDial.show();
}
}
catch (InterruptedException e)
{
System.exit(0);
}
}
catch (IOException e)
{
System.exit(0);
}
试试这个:
/**
* Checks if the device is rooted.
*
* @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
*/
public static boolean isRooted() {
// get from build info
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
return true;
}
} catch (Exception e1) {
// ignore
}
// try executing commands
return canExecuteCommand("/system/xbin/which su")
|| canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
}
// executes a command on the system
private static boolean canExecuteCommand(String command) {
boolean executedSuccesfully;
try {
Runtime.getRuntime().exec(command);
executedSuccesfully = true;
} catch (Exception e) {
executedSuccesfully = false;
}
return executedSuccesfully;
}