当前位置: 代码迷 >> Android >> Android编程获取root权限后无法访问/root和/data文件夹解决办法
  详细解决方案

Android编程获取root权限后无法访问/root和/data文件夹解决办法

热度:32   发布时间:2016-05-01 21:15:06.0
Android编程获取root权限后无法访问/root和/data文件夹
文件管理器获取root权限后,注意获取成功!到真机上上测试也是提示获取权限成功,可是问题来了为啥这还访问不了/root等文件夹呢
权限获取代码:
Java code
/**     * 应用程序运行命令获取 Root权限,设备必须已破解(获得ROOT权限)     *      * @param command     *            命令:String apkRoot="chmod 777 "+getPackageCodePath();//RootCommand(apkRoot);     * @return 应用程序是/否获取Root权限     */    public static boolean RootCommand(String command) {        Process process = null;        DataOutputStream os = null;        try {            process = Runtime.getRuntime().exec("su");            os = new DataOutputStream(process.getOutputStream());            os.writeBytes(command + "\n");            os.writeBytes("exit\n");            os.flush();            process.waitFor();        } catch (Exception e) {            return false;        } finally {            try {                if (os != null) {                    os.close();                }                process.destroy();            } catch (Exception e) {            }        }        return true;    }


------解决方案--------------------
Process process = null;
DataOutputStream os = null;
try {String command = "chmod 777 " + "data";

process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {

} finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
}
}
这样可以访问data文件夹
------解决方案--------------------

String[] command={"su","-c","/data"}
Process=Runtime.getRuntime().exec(command);
process.waitfor();
os = new DataOutputStream(process.getOutputStream());

不知道这样行不行了~
  相关解决方案