Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1572|回复: 0
打印 上一主题 下一主题

判断手机是否有root权限

[复制链接]

697

主题

1142

帖子

4086

积分

认证用户组

Rank: 5Rank: 5

积分
4086
跳转到指定楼层
楼主
发表于 2018-7-13 21:06:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. public class RootUtil {
  2.     public static boolean isDeviceRooted() {
  3.         return checkRootMethod1() || checkRootMethod2() || checkRootMethod3();
  4.     }

  5.     private static boolean checkRootMethod1() {
  6.         String buildTags = android.os.Build.TAGS;
  7.         return buildTags != null && buildTags.contains("test-keys");
  8.     }

  9.     private static boolean checkRootMethod2() {
  10.         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",
  11.                 "/system/bin/failsafe/su", "/data/local/su", "/su/bin/su"};
  12.         for (String path : paths) {
  13.             if (new File(path).exists()) return true;
  14.         }
  15.         return false;
  16.     }

  17.     private static boolean checkRootMethod3() {
  18.         Process process = null;
  19.         try {
  20.             process = Runtime.getRuntime().exec(new String[] { "/system/xbin/which", "su" });
  21.             BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
  22.             if (in.readLine() != null) return true;
  23.             return false;
  24.         } catch (Throwable t) {
  25.             return false;
  26.         } finally {
  27.             if (process != null) process.destroy();
  28.         }
  29.     }

  30. }
复制代码
调用
  1. if (isDeviceRooted()){
  2.             Log.d(TAG, "onCreate: 你的设备可以获取root");
  3.         }else {
  4.             Log.d(TAG, "onCreate: 你的设备可以获取不能获取root");
  5. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-4-20 21:13 , Processed in 0.055355 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表