Android Runtime.getRuntime (). Exec ("su") java.io.IOException: Permission denied

When I use this code:

process = Runtime.getRuntime().exec("su"); os = new DataOutputStream(process.getOutputStream()); 

is there always a mistake, any ideas? Running on an Android virtual device.

 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 
+5
source share
2 answers

You tried to add this permission

 <uses-permission android:name="android.permission.ACCESS_SUPERUSER"/> 
+1
source

Called: java.io.IOException: Permission denied

  • find where su, for example: /system/xbin/su
  • check su file resolution: ls -al /system/xbin/su
  • if necessary, change the mode: chmod 4755 su
  • try again.
0
source

Source: https://habr.com/ru/post/1236814/


All Articles