Android 应用Root权限申请实现

概述

app在root过的设备当中申请root权限。
 

实现

public static boolean isRoot()
    {
        Process process = null;
        DataOutputStream os = null;
        try
        {
            process = Runtime.getRuntime().exec(“su”);
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(“exit\n”);
            os.flush();
            int exitValue = process.waitFor();
            if (exitValue == 0)
            {
                return true;
            } else
            {
                return false;
            }
        } catch (Exception e)
        {
            Log.d(TAG, “Unexpected error – Here is what I know: “
                    + e.getMessage());
            return false;
        } finally
        {
            try
            {
                if (os != null)
                {
                    os.close();
                }
                process.destroy();
            } catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    }
合作联系邮箱:cofface#cofface.com(请将#替换为@)

转载请注明来源:Cofface Blog » Android 应用Root权限申请实现

赞 (33) 打赏

感谢您的支持,我会继续努力的!

支付宝扫一扫打赏