android - 更改应用程序中的文件权限

标签 android shell

我尝试更改应用程序中的文件权限。代码如下:

Runtime.getRuntime().exec("chmod 777 /sdcard/test.txt");

此代码在我的应用程序中不起作用,但没有错误日志。 我还检查了/system/bin 下的 shell 工具,发现 chmod 在/system/bin 下,但其他一些信息显示 chmod > 工具箱。我不清楚这一点。我的应用程序使用了 android:sharedUserId="android.uid.system"。 如何运行此代码或如何更改文件的权限?非常感谢。

最佳答案

Runtime rt = Runtime.getRuntime();
Process proc;
try {
    proc = rt.exec(new String[] { "su", "-c", "chmod 777 " + Constants.filename });
    proc.waitFor();
} catch (Exception e){ //DOSTUFFS }

这应该可以解决问题

关于android - 更改应用程序中的文件权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8412384/

相关文章:

node.js - 使用命令扩展运行 NPM 脚本会在返回结果之前解析结果 - 与 bash 不同

bash - 如何在 bash shell 的 if 语句中使用 ls 命令的输出

javascript - nodejs child_processes.exec 无法返回 'nohup' 命令

android - Gradle 同步失败 : Uninitialized object exists on backward branch 70

android - MVVM 在 MvxBindableListView 中交叉更改 ViewModel

android - 编译 LOCAL_SRC_FILES 时 Cocos2d-x 错误指向丢失的文件(和文件夹)Windows

python - 如何通过python循环执行linux命令

android - 旋转手机时如何最好地重新创建标记/折线(方向更改)

android - 从其他应用程序接收多个文件无法按预期工作

regex - Grep/Sed 每次出现换行符后跟 bash 中的字符串