陕西国防工业职业技术学院,www.sesehu.con,诛仙往生咒
root权限是安卓最高的操作权限,俗称superuser,简称su,一般来说root过的手机,系统目录会有su目录和系统app目录中有Superuser.apk,或者kingroot、360Root、Root精灵、等apk。当然了,在安卓8系列中会使用magisk,文件名就不一样了。下面是RootUtil文件,实现三种检测方法来判断是否有root
public class RootUtil { public static boolean isDeviceRooted() { return checkRootMethod1() || checkRootMethod2() || checkRootMethod3(); } private static boolean checkRootMethod1() { String buildTags = android.os.Build.TAGS; return buildTags != null && buildTags.contains("test-keys"); } private static boolean checkRootMethod2() { 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; } private static boolean checkRootMethod3() { Process process = null; try { process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" }); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); if (in.readLine() != null) return true; return false; } catch (Throwable t) { return false; } finally { if (process != null) process.destroy(); } } }
调用方法
if (isDeviceRooted()){ Log.d(TAG, "onCreate: 你的设备可以获取root"); }else { Log.d(TAG, "onCreate: 你的设备可以获取不能获取root"); }
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Android apk 项目一键打包并上传到蒲公英的实现方法
Android 自定义LineLayout实现满屏任意拖动功能的示例代码
android 限制某个操作每天只能操作指定的次数(示例代码详解)
Android 集成 google 登录并获取性别等隐私信息的实现代码
网友评论