参见英文答案 > Determine if running on a rooted device 20个
我如何检查AndroID设备是否已植根?我使用以下代码:
Process proc = Runtime.getRuntime ().exec ("su");
当我在设备上运行它时,我得到了以下异常.
Causes by:Permission denIEd
但是在模拟器上运行不会给出任何异常.
我正在使用另一种方式来检查.在模拟器的命令行中输入adb shell返回#,但是对于设备编写,adb shell会出现以下错误:
shell@androID:/ $su su /system/bin/sh: su: not found 127|shell@androID:/ $
那么如何检查设备是否已植根.
提前致谢.
最佳答案我用这个班:private voID CheckRoot() { Process p; try { // Preform su to get root privledges p = Runtime.getRuntime().exec("su"); // Attempt to write a file to a root-only DataOutputStream os = new DataOutputStream(p.getoutputStream()); os.writeBytes("echo \"Do I have root?\" >/data/LandeRootCheck.txt\n"); // Close the terminal os.writeBytes("exit\n"); os.flush(); try { p.waitFor(); if (p.exitValue() == 0) { // Todo Code to run on success this.IsRoot=true; } else { // Todo Code to run on unsuccessful this.IsRoot=false; } } catch (InterruptedException e) { // Todo Code to run in interrupted exception toastMessage("not root"); } } catch (IOException e) { // Todo Code to run in input/output exception toastMessage("not root"); } }
总结 以上是内存溢出为你收集整理的如何检查android设备是rooted设备?全部内容,希望文章能够帮你解决如何检查android设备是rooted设备?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)