![](/img/trans.png)
[英]How to check if the android device is rooted or not in Appcelerator?
[英]Android device rooted check
我想檢查我的設備是否植根。 當我在真實設備中嘗試下面的這段代碼時,它沒有扎根,沒關系。 但是非根模擬器在這一行中斷
if (new File(path).exists())
return true;
“/system/xbin/su”路徑存在。
private static boolean isRooted() {
String[] paths = { "/system/app/Superuser.apk", "/sbin/su", "/system/bin/su", "/system/xbin/su", "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
"/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
for (String path : paths) {
if (new File(path).exists())
return true;
}
return false;
}
Genymotion 或 Android Studio 的模擬器總是在代碼塊中中斷。
安卓模擬器都root了嗎?
您可以通過以下方法檢查設備是否植根:
public static boolean isRootedDevice(Context context) {
boolean rootedDevice = false;
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
Log.e("Root Detected", "1");
rootedDevice = true;
}
// check if /system/app/Superuser.apk is present
try {
File file = new File("/system/app/Superuser.apk");
if (file.exists()) {
Log.e("Root Detected", "2");
rootedDevice = true;
}
} catch (Throwable e1) {
//Ignore
}
//check if SU command is executable or not
try {
Runtime.getRuntime().exec("su");
Log.e("Root Detected", "3");
rootedDevice = true;
} catch (IOException localIOException) {
//Ignore
}
//check weather busy box application is installed
String packageName = "stericson.busybox"; //Package for busy box app
PackageManager pm = context.getPackageManager();
try {
Log.e("Root Detected", "4");
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
rootedDevice = true;
} catch (PackageManager.NameNotFoundException e) {
//App not installed
}
return rootedDevice;
}
如果設備已植根,它將返回true
否則返回false
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.