zoukankan      html  css  js  c++  java
  • android请求root权限

    应用获取Root权限的原理:让应用的代码执行目录获取最高权限。在Linux中通过chmod 777 [代码执行目录]

    //请求root权限
        public static boolean upgradeRootPermission(String pkgCodePath) {  
            Process process = null;  
            DataOutputStream os = null;  
            Boolean resBoolean;
            try {  
                String cmd="chmod 777 " + pkgCodePath;  
                process = Runtime.getRuntime().exec("su"); //切换到root帐号  
                os = new DataOutputStream(process.getOutputStream());  
                os.writeBytes(cmd + " ");  
                os.writeBytes("exit ");     //退出root 账号,不执行会卡住机器
                os.flush();  
                resBoolean= process.waitFor()==0;  
            } catch (Exception e) {  
                return false;  
            } finally {  
                try {  
                    if (os != null) {  
                        os.close();  
                    }  
                    process.destroy();  
                } catch (Exception e) {  
                }  
            }  
            return resBoolean;  
        }  
       

    //调用函数

    if(upgradeRootPermission(getPackageCodePath()))
            {
                Toast.makeText(MainActivity.this, "Root 权限请求成功", Toast.LENGTH_SHORT).show();
            }
            else{
                Toast.makeText(MainActivity.this, "Root 权限请求失败,无法使用!程序将自动退出!", Toast.LENGTH_SHORT).show();
                finish();
            }

  • 相关阅读:
    有关SQL的查询问题
    Nginx学习笔记——搭建Linux +Nginx+PHP+Mariadb(MySql)开发环境
    查询组列表时直接显示需要的组内成员
    MySql联合查询Union
    jQuery使用ajax方法提交登陆信息时,遇到特殊字符&
    ubuntu下安装LNMP环境
    Ubuntu下安装VirtualBox增强插件
    开启Apache,允许外部访问
    Windows下安装Memcached
    关于xls的一点笔记
  • 原文地址:https://www.cnblogs.com/lzh-Linux/p/4478793.html
Copyright © 2011-2022 走看看