如何以编程方式找到扎根的设备? [英] how to find the rooted device programmatically?
问题描述
安装我的应用程序之前,我想它来检查设备是否植根或not.I使用了下列code
Before installing my application,i want it to check whether the device is rooted or not.I have used the following code
private static boolean isRooted()
return findBinary("su");
}
public static boolean findBinary(String binaryName) {
boolean found = false;
if (!found) {
String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/",
"/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
for (String where : places) {
if ( new File( where + binaryName ).exists() ) {
found = true;
break;
}
}
}
return found;
}
据工作properly.But我听说过的文件名苏是可以改变的,也名为苏的文件可以在非根devices.In的情况下创建的,这个源不是dependable.so我想知道一些其他的方式找到比搜索苏以外的扎根设备。
我用下面的code
It is working properly.But i have heard that the filename "su" can be changed and also a file with the name "su" can be created in the nonrooted devices.In that cases,this source is not dependable.so i want to know some other way to find the rooted device other than searching for "su". I have used the following code
Public static boolean checkRootMethod1()
{
String buildTags = android.os.Build.TAGS;
if (buildTags != null && buildTags.contains("test-keys")) {
return true;
}
return false;
}
这是行不通的properly.For扎根它可以作为expected.But对于一些无根设备也它显示为rooted.Since输出variying为不同的设备的设备,我无法找到一个solution..any帮助将是$ AP p $ pciated
It is not working properly.For rooted devices it works as expected.But for SOME unrooted devices also it shows as rooted.Since the output is variying for differnt devices,i cannot find a solution..any help would be appreciated
推荐答案
试试下面code: -
try below code:-
/**
* 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;
}
见下面的链接: -
see below link:-
<一个href=\"http://stackoverflow.com/questions/3424195/determining-if-an-android-device-is-rooted-programatically\">Determining如果Android设备编程扎根?
这篇关于如何以编程方式找到扎根的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!