Код: Выделить всё
public String runAsRoot() {
try {
Process process = Runtime.getRuntime().exec("su root 'whoami'");
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
process.waitFor();
return output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
Код: Выделить всё
FATAL EXCEPTION: main (Ask Gemini)
Process: me.rapierxbox.test, PID: 9207
java.lang.RuntimeException: java.io.IOException: Cannot run program "su": error=13, Permission denied
at me.rapierxbox.test.MainActivity.runAsRoot(MainActivity.java:148)
at me.rapierxbox.test.MainActivity.lambda$onCreate$1$me-rapierxbox-test-MainActivity(MainActivity.java:50)
at me.rapierxbox.test.MainActivity$$ExternalSyntheticLambda3.onClick(D8$$SyntheticClass:0)
at android.view.View.performClick(View.java:5610)
Caused by: java.io.IOException: Cannot run program "su": error=13, Permission denied
at java.lang.ProcessBuilder.start(ProcessBuilder.java:983)
at java.lang.Runtime.exec(Runtime.java:691)
at java.lang.Runtime.exec(Runtime.java:524)
at java.lang.Runtime.exec(Runtime.java:421)
at me.rapierxbox.test.MainActivity.runAsRoot(MainActivity.java:131)
Подробнее здесь: https://stackoverflow.com/questions/795 ... 7-0-device
Мобильная версия