android - 如何在 Android 中使用 root 创建/删除 /data/data 目录中的文件?
问题描述
我正在开发一个 POC,我需要在其中创建并稍后删除/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());
}
推荐阅读
- c# - 使用正则表达式格式化文件
- django - 覆盖 queryset 'only' 方法 | 姜戈
- azure-devops - 从 Azure DevOps 中的 JFrog 工件还原生成依赖项
- tensorflow - Keras - 无法理解 RNN 单元
- arrays - Fortran 函数错误地接受错误形状的数组
- c# - 在 Blazor 中的两个子组件之间共享数据的最佳方式
- reactjs - React.memo 不起作用 - 我错过了什么?
- html - 单击链接时将类添加到链接,单击其他位置时将其删除
- wordpress - 浏览器不安全内容警告,db 或 WP 主题中没有 http://
- solr - SOLR:如何使用 edismax 提升多个值的结果?