学无先后,达者为师

网站首页 编程语言 正文

安卓给文件赋777读写权限

作者:短腿姑娘 更新时间: 2022-02-12 编程语言
private static boolean upgradeRootPermission(String path){
    Process process =null;
    DataOutputStream os = null;
    try {
        String cmd = "chmod 777 " + path;
        process = Runtime.getRuntime().exec("su");
        os = new DataOutputStream(process.getOutputStream());
        os.writeBytes(cmd + "\n");
        os.writeBytes("exit\n");
        os.flush();
        process.waitFor();
    }catch (Exception e){
    }finally {
        try {
            if (os != null){
                os.close();
            }
            process.destroy();
        }catch (Exception e){

        }
    }
try {
    return process.waitFor() == 0;
}catch (InterruptedException e){
    e.printStackTrace();
}
return false;
}

原文链接:https://blog.csdn.net/qq_42834405/article/details/117817687

栏目分类
最近更新