<分区>
我想以编程方式在我的应用程序中查找 android 手机是否已 Root 。我发现了很多链接,例如:Determine if running on a rooted device Effective way to programatically check if I'm rooted on Android?讨论同一个话题。但是,正如这些链接中所提到的,没有一种明确的方法可以找出答案。这些帖子已经很老了,我想知道在最近的版本中是否有更好的方法来实现它?
提前致谢!
<分区>
我想以编程方式在我的应用程序中查找 android 手机是否已 Root 。我发现了很多链接,例如:Determine if running on a rooted device Effective way to programatically check if I'm rooted on Android?讨论同一个话题。但是,正如这些链接中所提到的,没有一种明确的方法可以找出答案。这些帖子已经很老了,我想知道在最近的版本中是否有更好的方法来实现它?
提前致谢!
最佳答案
我已经从 RootTools 包装了这段代码(没有任何其他外部 jar/lib 也能正常工作)
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;
}
关于android - 如何查看安卓手机是否root?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19288463/