I am trying to execute commands from my android app, in order to configure some aspects of my device by code. For example, I am trying to lock my device using this code (from a class that extends the class MainActivity):
Process p=Runtime.getRuntime().exec("su");
DataOutputStream dos = new DataOutputStream(p.getOutputStream());
dos.writeBytes("adb shell input keyevent 26");
dos.writeBytes("exit\n");
dos.flush();
dos.close();
p.waitFor();
When I run it, I receive:
java.io.Exception: Error running exec(). Command: [su] Working directory: null Environment: null
My device is not rooted. I have tried others ways to do that, but have been unsuccessful.
Any idea?