如何在 Android 中使用 root 创建/删除 /data/data 目录中的文件?
How can one create/ delete files in the /data/data dir using root in Android?
我正在开发一个 POC,我需要在其中创建并稍后删除 root 设备的 /data/data
目录中的文件。我试图以标准方式创建文件,但它按预期抛出 PERMISSION_DENNIED
异常。
我知道这是可能的,因为 Root Explorer 应用程序可以做到。
如何通过 root 以编程方式创建/删除文件?
提前致谢!
根据@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());
}
我正在开发一个 POC,我需要在其中创建并稍后删除 root 设备的 /data/data
目录中的文件。我试图以标准方式创建文件,但它按预期抛出 PERMISSION_DENNIED
异常。
我知道这是可能的,因为 Root Explorer 应用程序可以做到。
如何通过 root 以编程方式创建/删除文件?
提前致谢!
根据@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());
}