I am trying to batch some apps installations and I want to do it app by app.
I am trying to get the adb command response into my java program but I don't manage to understand why I don't get anything from an InputStream
!
Here is my test code:
import java.io.IOException;
import java.io.InputStream;
public class main_adbStreamTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Process pro = Runtime.getRuntime().exec("platform-tools\\adb.exe -s " + args[0] + ":5555 install -r " + args[1]); // + " >> " + SBCWLogger.getFileHandlerName()
//add installation verification
InputStream is = pro.getInputStream();
int i = 0;
while( (i = is.read() ) != -1) {
System.out.print((char)i);
}
//verification done
} catch (IOException e) {
e.printStackTrace();
}
}
}
I found this answer which is not working, and I do not manage to use pro.getInputStream()
properly either.
I also tried most of the answers from here but none of those I tested worked. I successfully read the errors when I don't connect or when the install fails, but not the informational messages as Success
at the end of an install. And that is what I want.
EDIT: the code below is working thanks to Onix' answer.
import java.io.IOException;
import java.io.InputStream;
public class main_adbStreamTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Process pro = new ProcessBuilder("platform-tools\\adb.exe", "-s",args[0], "install", "-r", args[1]).start();
//add installation verification
InputStream is = pro.getInputStream();
int i = 0;
while( (i = is.read() ) != -1) {
System.out.print((char)i);
}
//verification done
} catch (IOException e) {
e.printStackTrace();
}
}
}
And to get the famous Success
, just write the stream to a file and read the last row.