Android:改变build.prop的方法

时间:2012-07-15 07:17:20

标签: android linux-kernel root tweak

我需要构建一个应用程序,它允许我使用自己的应用程序编辑build.prop。这是为了优化build.prop中的一些值。当然,我可以使用具有root访问权限的文件管理器编辑此文件。但我的问题是,我需要使用我创建的应用程序对其进行编辑,并使新手用户可以轻松地使用我的应用程序推荐的设置来编辑文件。请帮我解决这个问题。谢谢你的时间!

1 个答案:

答案 0 :(得分:3)

这样的事情应该有效。 代码尚未经过测试,可能需要进行一些更改

请求超级用户访问

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);

在这里编辑String content

写文件

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

请记住在编辑过程中出现问题时备份build.prop。