2

Is there a way to start adb shell from application/java code? I have followed below method. But everytime it only shows "device not found". However am able to get the logs if am executing "adb logcat -f /storage/emulated/0/logs.txt &" .I have even enabled USB debugging on the device. Kindly help me if any1 knows any other alternative.

try{
 Runtime runtime = Runtime.getRuntime();
 Process process = runtime.exec("adb shell");
}
catch(Exception e){
}
Amulya Holla
  • 83
  • 1
  • 7
  • Have you checked these questions [1](http://stackoverflow.com/questions/13381828/is-it-possible-to-execute-adb-commands-through-my-android-app) & [2](http://stackoverflow.com/questions/13381828/is-it-possible-to-execute-adb-commands-through-my-android-app) ? – Saurabh Meshram Sep 19 '14 at 09:35
  • Yes I have checked them. none of them worked for "adb shell" command. The same worked for "adb logcat " command – Amulya Holla Sep 19 '14 at 13:00

1 Answers1

0
try {
   Runtime runtime = Runtime.getRuntime();

   Process process = runtime.exec("E:\\Android\\sdk\\platform-tools\\adb shell");
   } catch (Exception e) {
   System.out.println("dasd");
}

E:\Android\sdk\platform-tools\ is my path of adb,(replays with yuors)

Nooh
  • 1,548
  • 13
  • 21
  • I have checked this. this gave 09-19 18:12:23.311: W/System.err(22771): java.io.IOException: Error running exec(). Command: [D:\adt-bundle-windows-x86\sdk\platform-tools\adb, shell] Working Directory: null Environment: null – Amulya Holla Sep 19 '14 at 12:59
  • Its problem with automatic termination of cmd after program completion – Nooh Sep 22 '14 at 08:47