Android 判断是否得到 root权限
16lz
2021-01-23
public synchronized boolean getRootAhth(){Process process = null;DataOutputStream os = null;try{process = Runtime.getRuntime().exec("su");os = new DataOutputStream(process.getOutputStream());os.writeBytes("exit\n");os.flush();int exitValue = process.waitFor();if (exitValue == 0){return true;} else{return false;}} catch (Exception e){Log.d("*** DEBUG ***", "Unexpected error - Here is what I know: "+ e.getMessage());return false;} finally{try{if (os != null){os.close();}process.destroy();} catch (Exception e){e.printStackTrace();}}}
方法二:
//判断机器 Android是否已经root,即是否获取root权限 protected static boolean haveRoot() { int i = execRootCmdSilent("echo test"); //通过执行测试命令来检测 if (i != -1) return true; retrun false; }
更多相关文章
- android 权限库,拿来就能用
- 【Android】Android permission 访问权限
- android 文件目录权限
- android 6.0权限问题处理的核心代码--shouldShowRequestPermissi
- Android中执行adb命令
- Android中的获取内存信息的相关命令
- android 6.0及以上危险权限的获取
- android需要的访问权限(不断更新,希望大家多交流)
- android 权限明细