Android(安卓)判断Root的方法
16lz
2021-01-24
分类:Android App 2013-08-03 09:51 691人阅读 评论(0) 收藏 举报
方法一:(不弹框)
[java] view plain copy- privatefinalstaticintkSystemRootStateUnknow=-1;
- privatefinalstaticintkSystemRootStateDisable=0;
- privatefinalstaticintkSystemRootStateEnable=1;
- privatestaticintsystemRootState=kSystemRootStateUnknow;
- publicstaticbooleanisRootSystem(){
- if(systemRootState==kSystemRootStateEnable){
- returntrue;
- }elseif(systemRootState==kSystemRootStateDisable){
- returnfalse;
- }
- Filef=null;
- finalStringkSuSearchPaths[]={"/system/bin/","/system/xbin/",
- "/system/sbin/","/sbin/","/vendor/bin/"};
- try{
- for(inti=0;i<kSuSearchPaths.length;i++){
- f=newFile(kSuSearchPaths[i]+"su");
- if(f!=null&&f.exists()){
- systemRootState=kSystemRootStateEnable;
- returntrue;
- }
- }
- }catch(Exceptione){
- }
- systemRootState=kSystemRootStateDisable;
- returnfalse;
- }
方法二:(会弹框)
[java] view plain copy- publicsynchronizedbooleangetRootAhth()
- {
- Processprocess=null;
- DataOutputStreamos=null;
- try
- {
- process=Runtime.getRuntime().exec("su");
- os=newDataOutputStream(process.getOutputStream());
- os.writeBytes("exit\n");
- os.flush();
- intexitValue=process.waitFor();
- if(exitValue==0)
- {
- returntrue;
- }else
- {
- returnfalse;
- }
- }catch(Exceptione)
- {
- Log.d("***DEBUG***","Unexpectederror-HereiswhatIknow:"
- +e.getMessage());
- returnfalse;
- }finally
- {
- try
- {
- if(os!=null)
- {
- os.close();
- }
- process.destroy();
- }catch(Exceptione)
- {
- e.printStackTrace();
- }
- }
- }
方法三:(会弹框)
- //判断机器Android是否已经root,即是否获取root权限
- protectedstaticbooleanhaveRoot()
- {
- inti=execRootCmdSilent("echotest");//通过执行测试命令来检测
- if(i!=-1)returntrue;
- retrunfalse;
- }
更多相关文章
- Android缓存理解
- Android(安卓)数据漫游默认值的修改方法
- Android(安卓)SystemService类注释
- Android实现使用流媒体播放远程mp3文件的方法
- Android开发 System.out.println(); 控制台输出方法
- Android简单判断某个APK是否已经安装的方法
- Flutter跟Android交互
- SimpleAdapter
- android 权限配置和测试环境配置