Android如何判断是否成功获得root权限 androidrootsuboolean 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用下面方法 // 判断机器Android是否已经root,即是否获取root权限 protected static boolean haveRoot() { int i = execRootCmdSilent("echo test"); // 通过执行测试命令来检测 if (i != -1) { return true; } return false; } 我想判断在请求Root时,用户点了允许还是拒绝 你这 execRootCmdSilent都不提供,楼主肯定没办法的,直接执行su就行了 你这 execRootCmdSilent都不提供,楼主肯定没办法的,直接执行su就行了不好意思,忘记了,补上 protected static int execRootCmdSilent(String paramString) { try { Process localProcess = Runtime.getRuntime().exec("su"); Object localObject = localProcess.getOutputStream(); DataOutputStream localDataOutputStream = new DataOutputStream( (OutputStream) localObject); String str = String.valueOf(paramString); localObject = str + "\n"; localDataOutputStream.writeBytes((String) localObject); localDataOutputStream.flush(); localDataOutputStream.writeBytes("exit\n"); localDataOutputStream.flush(); localProcess.waitFor(); int result = localProcess.exitValue(); return (Integer) result; } catch (Exception localException) { localException.printStackTrace(); return -1; } } localProcess.waitFor(); 这句在某些手机如,酷派4.4上会停滞没有反应,判断失败! private final static int kSystemRootStateUnknow=-1; private final static int kSystemRootStateDisable=0; private final static int kSystemRootStateEnable=1; private static int systemRootState=kSystemRootStateUnknow; public static boolean isRootSystem() { if(systemRootState==kSystemRootStateEnable) { return true; } else if(systemRootState==kSystemRootStateDisable) { return false; } File f=null; final String kSuSearchPaths[]={"/system/bin/","/system/xbin/","/system/sbin/","/sbin/","/vendor/bin/"}; try{ for(int i=0;i<kSuSearchPaths.length;i++) { f=new File(kSuSearchPaths[i]+"su"); if(f!=null&&f.exists()) { systemRootState=kSystemRootStateEnable; return true; } } }catch(Exception e) { } systemRootState=kSystemRootStateDisable; return false; }通过su文件是否存在来判断 做个安卓手机上的视频播放器? 谷歌地图api如何注册 一个颜色替换的问题 写的android例子程序报错:the application has stopped android cursor 问题 Android能与gwt配合使用吗? ScrollView怎么设置定位标记啊? HTC G7 无法定位的问题 华为推送除了能帮助开发者解决技术问题,还有什么好处啊? GridView 焦点问题 如何获取ListView的Item的高度 eclipse导入工程
// 判断机器Android是否已经root,即是否获取root权限
protected static boolean haveRoot() {
int i = execRootCmdSilent("echo test"); // 通过执行测试命令来检测
if (i != -1) {
return true;
}
return false;
}
你这 execRootCmdSilent都不提供,楼主肯定没办法的,直接执行su就行了
你这 execRootCmdSilent都不提供,楼主肯定没办法的,直接执行su就行了不好意思,忘记了,补上
protected static int execRootCmdSilent(String paramString) {
try {
Process localProcess = Runtime.getRuntime().exec("su");
Object localObject = localProcess.getOutputStream();
DataOutputStream localDataOutputStream = new DataOutputStream(
(OutputStream) localObject);
String str = String.valueOf(paramString);
localObject = str + "\n";
localDataOutputStream.writeBytes((String) localObject);
localDataOutputStream.flush();
localDataOutputStream.writeBytes("exit\n");
localDataOutputStream.flush();
localProcess.waitFor();
int result = localProcess.exitValue();
return (Integer) result;
} catch (Exception localException) {
localException.printStackTrace();
return -1;
}
}
private final static int kSystemRootStateDisable=0;
private final static int kSystemRootStateEnable=1;
private static int systemRootState=kSystemRootStateUnknow;
public static boolean isRootSystem()
{
if(systemRootState==kSystemRootStateEnable)
{
return true;
}
else if(systemRootState==kSystemRootStateDisable)
{ return false;
}
File f=null;
final String kSuSearchPaths[]={"/system/bin/","/system/xbin/","/system/sbin/","/sbin/","/vendor/bin/"};
try{
for(int i=0;i<kSuSearchPaths.length;i++)
{
f=new File(kSuSearchPaths[i]+"su");
if(f!=null&&f.exists())
{
systemRootState=kSystemRootStateEnable;
return true;
}
}
}catch(Exception e)
{
}
systemRootState=kSystemRootStateDisable;
return false;
}通过su文件是否存在来判断