如何编辑属于其他应用程序的文件

时间:2015-10-05 12:12:22

标签: android

我想编辑属于不同应用程序的文件。是否有程序化的方式,以便我可以做到这一点,而无需根电话?

到目前为止,每当我尝试这样做时,我都会“打开失败”:EACCES(权限被拒绝)错误。

    try {
        File sd = Environment.getExternalStorageDirectory();
        File data = Environment.getDataDirectory();

        if (sd.canWrite()) {
            String currentDBPath = "//data//com.someapp//some_file.xml";
            String backupDBPath = "destfile.xml";
            File currentDB = new File(data, currentDBPath);
            File backupDB = new File(sd, backupDBPath);

            if (currentDB.exists()) {
                Toast.makeText(this, "app found", Toast.LENGTH_LONG).show();
                FileChannel src = new FileInputStream(currentDB).getChannel();
                FileChannel dst = new FileOutputStream(backupDB).getChannel();
                dst.transferFrom(src, 0, src.size());
                src.close();
                dst.close();
            }
        }
    } catch (Exception e) {
        Toast.makeText(this, "Err: "+e,Toast.LENGTH_LONG).show();
    }

Toast“app found”出现表明源文件有效,但在此之后,它会抛出打开失败,权限被拒绝错误。

在try块中尝试下面,但似乎 - 它没有被执行,而是执行了catch语句。

Process process = Runtime.getRuntime().exec("su");

0 个答案:

没有答案