【问题标题】:How to chmod folder data/data/com.example.anotherapp如何 chmod 文件夹 data/data/com.example.anotherapp
【发布时间】:2014-08-30 09:36:02
【问题描述】:

我制作了一个应用程序来使用 roottools 备份和恢复应用程序和数据。

我将文件夹 data/data/com.example.anotherapp 备份到 sdcard。现在,我卸载/重新安装并将文件夹 com.example.anotherapp 复制到 data/data/ 但应用程序无法运行。

如何 chmod 文件夹 com.example.anotherapp?

    public static boolean restoreDatabase(Context context, AppManagerItem item) {
    String from = "/data/data/";
    File fileOut = new File(Environment.getExternalStorageDirectory(),
            context.getString(R.string.app_name));
    String to = fileOut.getAbsolutePath() + File.separator
            + item.getPackageName();

    to = normalizeParameter(to);
    boolean isSuccess = false;

    String comando = "cp -r " + to + " " + from;

    Process suProcess;
    try {
        suProcess = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(
                suProcess.getOutputStream());
        os.writeBytes(comando + "\n");
        os.flush();
        os.writeBytes("exit\n");
        os.flush();
        try {
            int suProcessRetval = suProcess.waitFor();
            if (255 != suProcessRetval) {
                // Acceso Root concedido
                isSuccess = true;
            } else {
                // Acceso Root denegado
                isSuccess = false;
            }
        } catch (Exception ex) {
            Log.w("Error ejecutando el comando Root", ex);
        }

        String chmod = "chmod -R 757 " + from + item.getPackageName();
        Runtime.getRuntime().exec(chmod);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return isSuccess;
}

谢谢。

【问题讨论】:

    标签: android backup directory restore chmod


    【解决方案1】:

    你可以这样做:

    String path = "/yourFolder";
    String[] chmod = { "su", "-c","chmod 777 "+path };
    try {
        Runtime.getRuntime().exec(chmod);
    } catch (IOException e) {
        e.printStackTrace();
    }
    

    【讨论】:

    • 谢谢,已经chmod了,但应用程序恢复后无法正常工作。 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-15
    相关资源
    最近更新 更多