I want to push a file from my Java program to an Android emulator. Now, I can launch the emulator by using ProcessBuilder and also trap the logcat messages. But whenever I'm trying to use the adb push command in process builder, the process hangs and no output is generated.
The code:
try {
ProcessBuilder proc = new ProcessBuilder("D://android-sdk//platform-tools//adb.exe",
"push D:\\final.xml /mnt/sdcard/final.xml");
Process p = proc.start();
BufferedReader br2 = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ( (line = br2.readLine()) != null)
System.out.println(line);
} catch (Exception e) {
System.err.println("Error");
}
EDIT:- Found the probabble solution. I was using Process.waitFor() method but not storing its returned exitcode. Now as i did this:
int exitVal = p.waitFor();
Everything worked as a charm.
And @Marc Van Daele Thanks for your input. as per my experience, ProcessBuilder works in both ways ie. You can use arguments separated by spaces or by commas. :)
Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.
A wrapper over android-adb, implemented using ES6 and along with async/await . This package is mainly used by Appium to perform all adb operations on android device.
Shouldn't this be separate arguments like
ProcessBuilder proc = new ProcessBuilder("D://android-sdk//platform-tools//adb.exe", "push", "D:\\final.xml", "/mnt/sdcard/final.xml");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With