Is it possible to execute adb commands through my android app?
You can do it with this:
Process process = Runtime.getRuntime().exec("your command");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
Don't forget to surround it with a try and catch statement.
Edit:
@Phix is right, ProcessBuilder would be better to use.
Normal Android apps have different privileges to processes started via adb
, e.g., processes started via adb
are allowed to the capture the screen whereas normal apps aren't. So, you can execute commands from your app via Runtime.getRuntime().exec()
, but they won't have the same privileges as if you had executed from an adb shell
.