Android:改变build.prop的方法

标签 android linux-kernel root tweak

我需要构建一个应用程序,使我能够使用自己的应用程序编辑 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/

相关文章:

android - onRestoreInstanceState 未被调用

android - 如何删除Android Studio中的 "call requires permission which may.."错误

c - 如何获取函数在调用栈中的位置?

linux - linux内核中内存屏障的目的

android - 如何从网络时间协议(protocol)获取当前时间?

android - 发行版本变体因 “androidx.fragment:fragment-testing”库的debugImplementation失败

c - 用pthread制作用户空间线程库,如何正确创建第一个线程? (前 2 个线程)

apache2 - 如何在apache2中创建多个文档根

linux - 如何克隆root用户

java - logcat 中应用程序强制关闭并出现 NullPointerException