Android:改变build.prop的方法



我需要构建一个应用程序,使我能够使用自己的应用程序编辑build.prop。这是为了优化build.prop中的一些值。当然,我可以使用具有root访问权限的文件管理器来编辑这个文件。但我的问题是,我需要使用我创建的应用程序来编辑这个文件,并让新手用户可以很容易地使用我的应用程序推荐的设置来编辑文件。请帮我弄清楚这个。谢谢你抽出时间!

这样的东西应该可以工作代码尚未测试,可能需要进行一些更改

请求超级用户访问

process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("mount -o remount rw /system/n"); 
os.writeBytes("exitn");
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);

在此处编辑String content

写入文件

DataOutputStream outstream= new DataOutputStream(new FileOutputStream(file,false));
String body = content;
outstream.write(body.getBytes());
outstream.close();

请记住备份build.prop,以防在编辑过程中出现问题

最新更新