我是Android的新手。我正在尝试运行shell命令来重命名系统中的文件。我有超级用户权限访问它。
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");
}发布于 2013-04-09 18:36:32
通过在进程的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();发布于 2013-04-09 18:52:06
您需要每个命令都处于与su相同的进程中,因为切换到根目录并不适用于您的应用程序,它适用于su,它在您到达mount之前完成。
相反,可以尝试两个exec:
...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会成功。这里的“正确路径”因制造商不同而不同,但可以通过编程来收集。
https://stackoverflow.com/questions/15899414
复制相似问题