【发布时间】:2012-08-03 01:59:18
【问题描述】:
我真的什么都试过了:
- NetHackFileHelpers
- How to get File Permission Mode programmatically in Java
- Change file permission in application
- Mount R/W system in android application to edit Read Only files
现在,假设我以 root 身份重新挂载,因此对文件系统具有 RW 权限(Android 版本 2.3.7):
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes("chmod -c 0777 /system/etc/customization/settings/com/android/browser/custom_settings.xml\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
或:
Process process = Runtime.getRuntime().exec("su -c \"/system/etc/customization/settings/com/android/browser/custom_settings.xml\"");
或:
Class<?> fileUtils = Class.forName("android.os.FileUtils");
Method setPermissions =
fileUtils.getMethod("setPermissions", String.class, int.class, int.class, int.class);
int a = (Integer) setPermissions.invoke(null, "/system/etc/customization/settings/com/android/browser/custom_settings.xml", 0777, -1, -1);
行为是相同的:没有任何反应。而如果我来自 adb shell 的chmod 工作正常。如何在我的代码中更改该文件的权限?
【问题讨论】:
标签: android permissions