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文件是否存在来判断 android中ListView android 如何阻止activity的back行为 查找程序错误 监控应用程序的启动与关闭、 求救啊!通过button的点击事件来事件viewflipper的切换 如何学习android系统和底层的东西 怎么获得Canvas中的一个像素点的颜色值 关于Android的流程图App开发 android如何实现路由转发功能?求解 求助!这个空指针的bug'boolean android.graphics.Bitmap.compress‘该怎么改? 如何获取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文件是否存在来判断