当我使用此代码时:
process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());
始终存在错误,有任何想法吗?在Android虚拟设备上运行
W/System.err(3211): java.io.IOException: Error running exec(). Command: [su] Working Directory: null Environment: null
W/System.err(3211): at java.lang.ProcessManager.exec(ProcessManager.java:211)
W/System.err(3211): at java.lang.Runtime.exec(Runtime.java:174)
W/System.err(3211): at java.lang.Runtime.exec(Runtime.java:247)
W/System.err(3211): at java.lang.Runtime.exec(Runtime.java:190)
W/System.err(3211): at com.example.executeandroidtest.ShellUtils.execCommand(MainActivity.java:661)
W/System.err(3211): at com.example.executeandroidtest.MainActivity$3.run(MainActivity.java:410)
W/System.err(3211): at java.lang.Thread.run(Thread.java:818)
W/System.err(3211): Caused by: java.io.IOException: Permission denied
W/System.err(3211): at java.lang.ProcessManager.exec(Native Method)
W/System.err(3211): at java.lang.ProcessManager.exec(ProcessManager.java:209)
W/System.err(3211): ... 6 more
答案 0 :(得分:2)
引起:java.io.IOException:Permission denied
/system/xbin/su
ls -al /system/xbin/su
chmod 4755 su
答案 1 :(得分:0)
您是否尝试添加此权限
<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>