1

我正在开发一个 POC,我需要在其中创建并稍后删除/data/data根设备目录中的文件。我尝试以标准方式创建文件,但它PERMISSION_DENNIED按预期抛出异常。我知道这是可能的,因为 Root Explorer 应用程序可以做到。

如何通过 root 以编程方式创建/删除文件?

预先感谢!

4

1 回答 1

0

基于@GabeSechan 评论,我能够使用此命令实现此目的。

创建新文件:

final String[] sCommand = {"su", "-c", "touch /data/..."};
        try {
            Runtime.getRuntime().exec(sCommand);

        } catch (Exception e) {
            Log.e(TAG, "Issue occurred while creating new file " + e.getMessage());
        }
    }

并删除文件:

final String[] sCommand = {"su", "-c", "rm /data/..."};
try {
    Runtime.getRuntime().exec(sCommand);

} catch (Exception e) {
    Log.e(TAG, "Issue occurred while deleting " + e.getMessage());
}
于 2019-04-08T15:07:04.020 回答