我需要构建一个应用程序,使我能够使用自己的应用程序编辑 build.prop。这是为了优化 build.prop 中的一些值。当然,我可以使用具有根访问权限的文件管理器来编辑此文件。但我的问题是,我需要使用我创建的应用程序来编辑它,并让新手用户可以轻松地使用我的应用程序推荐的设置来编辑文件。请帮我弄清楚这一点。感谢您的宝贵时间!
最佳答案
像这样的东西应该可以工作。 代码尚未经过测试,可能需要一些更改
请求 super 用户访问权限
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("mount -o remount rw /system/\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
File file=new File("/system/build.prop");
读取文件
FileInputStream fis = openFileInput("/system/build.prop");
String content = "";
byte[] input = new byte[fis.available()];
while (fis.read(input) != -1) {}
content += new String(input);
在此处编辑字符串内容
。
写入文件
DataOutputStream outstream= new DataOutputStream(new FileOutputStream(file,false));
String body = content;
outstream.write(body.getBytes());
outstream.close();
记得备份您的 build.prop 以防在编辑过程中出现问题。
关于Android:改变build.prop的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11490197/