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.com:Cofface Blog » Android 应用Root权限申请实现

赞 (18) 打赏

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

支付宝扫一扫打赏

微信扫一扫打赏