Run the command to enter adb shell command from apk

I am trying to execute the swipe command from my Apk using

process = Runtime.getRuntime (). exec ("adb shell input 300 300 -800 300");

but nothing happens and no error occurs at runtime.

Do I need to add anything to the manifest to make it work?

+1
source share
2 answers

You can only execute / system / bin / input as the root user or shell; this will not work in the application. The command should not start with the "adb shell" when launched from the application.

To run a command with root privileges:

Process su = null; try { su = Runtime.getRuntime().exec("su"); su.getOutputStream().write("input swipe 250 300 -800 300\n".getBytes()); su.getOutputStream().write("exit\n".getBytes()); su.waitFor(); } catch (Exception e) { e.printStackTrace(); } finally { if (su != null) { su.destroy(); } } 

You should also check out third-party libraries to handle su commands: https://android-arsenal.com/details/1/451

+3
source

You need to set the permission of INJECT_EVENTS in the manifest:

 uses-permission android: name = "android.permission.INJECT_EVENTS"

0
source

All Articles