我真的什么都试过了:
NetHackFileHelpers How获取文件权限模式编程在Java中 更改文件权限 Mount在Android应用程序来编辑R / W系统只读文件 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现在,假设我已经重新安装的根,因此 RW
文件系统(Android版本2.3.7)的权限:
Now, suppose I've remounted as root, and therefore RW
permission on file system (Android version 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);
的行为是一样的:没有任何反应。而如果我搭配chmod
亚行的shell工作正常。我怎样才能从我的code更改该文件的权限?
The behaviour is the same: nothing happens. Whereas if I chmod
from adb shell works fine. How can I change the permissions of that file from within my code?
下面是我的解决办法:
Process sh = Runtime.getRuntime().exec("su", null, new File("/system/bin/"));
OutputStream os = sh.getOutputStream();
os.write(("chmod 777 <filepath>").getBytes("ASCII"));
os.flush();
os.close();
sh.waitFor();