![](/img/trans.png)
[英]How to read the SMS using shell commands In Rooted android Device?
[英]How to run rename shell command in android app (rooted)
我是Android新手。 我正在嘗試運行shell命令以重命名系統中的文件。 我有root訪問權限。
shell命令:
$ su
# mount -o remount,rw /system
# mv system/file.old system/file.new
我已經嘗試過了,但是沒有用:
public void but1(View view) throws IOException{
Process process = Runtime.getRuntime().exec("su");
process = Runtime.getRuntime().exec("mount -o remount,rw /system");
process = Runtime.getRuntime().exec("mv /system/file.old system/file.new");
}
通過在進程的OuputStream
編寫命令,您可以使用同一進程運行多個命令。 這樣,命令將在與su
命令相同的上下文中運行。 就像是:
Process process = Runtime.getRuntime().exec("su");
DataOutputStream out = new DataOutputStream(process.getOutputStream());
out.writeBytes("mount -o remount,rw /system\n");
out.writeBytes("mv /system/file.old system/file.new\n");
out.writeBytes("exit\n");
out.flush();
process.waitFor();
您需要使每個命令與su
處於同一進程中,因為切換到root不適用於您的應用程序,因此它適用於su
,該過程在mount
之前完成。
相反,請嘗試兩個執行程序:
...exec("su -c mount -o remount,rw /system");
...exec("su -c mv /system/file.old system/file.new");
另外,請注意,我已經看到某些系統在mount -o remount,rw /system
會失敗,但是在mount -o remount,rw /dev/<proper path here> /system
會成功。 每個制造商的“此處正確路徑”不同,但可以通過編程收集。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.