Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to execute adb commands through my android app?

Tags:

android

adb

Can anyone say, whether adb commands can be executed through my android application. If it is possible to execute, how it can be implemented?

like image 231
RajeshVijayakumar Avatar asked Nov 14 '12 15:11

RajeshVijayakumar


People also ask

Can you run adb commands on Android phone?

To use ADB with your Android device, you must enable a feature called “USB Debugging.” Open your phone's app drawer, tap the Settings icon, and select “About Phone”. Scroll all the way down and tap the “Build Number” item seven times. You should get a message saying you are now a developer.

How do I run ADB from a specific device?

Use the -s option followed by a device name to select on which device the adb command should run. The -s options should be first in line, before the command.


1 Answers

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.

like image 165
Ahmad Avatar answered Sep 20 '22 19:09

Ahmad