I am trying to make a simple Java application to install the APK on Android devices connected via USB. Using ABD manually, everything works fine, but I wanted to give a simple one-click installation option in my application, but for some reason the code does not work:
try {
abdsourcesync = apkpath;
progress.setString("sync in progress");
System.out.println("Starting Sync via adb with command " + "adb"
+ " install -r " + apkpath);
Process process = Runtime.getRuntime().exec(
"adb" + " install -r " + apkpath);
InputStreamReader reader = new InputStreamReader(
process.getInputStream());
Scanner scanner = new Scanner(reader);
scanner.close();
int exitCode = process.waitFor();
System.out.println("Process returned: " + exitCode);
The process ends with status 141, but no other errors that I can see, but when I look at the tablet, the .APK program is not installed. I made sure that the space was shortened on the device and third-party applications were supported, etc. Therefore, I am sure that the problem is with my java and not with the Android device (as I said, if I run ADB install -r myself from terminal, then everything works fine).
stackoverflow, APK Android, Java.
;
EDIT: : ProcessBuilder adb:
try {
abdsourcesync = apkpath;
progress.setString("sync in progress");
System.out.println("Starting Sync via adb with command " + "adb"
+ " install -r " + apkpath);
ProcessBuilder apksync = new ProcessBuilder("adb", " install -r ", apkpath);
apksync = apksync.redirectErrorStream(true);
Process process = apksync.start();
InputStreamReader reader = new InputStreamReader(
process.getInputStream());
Scanner scanner = new Scanner(reader);
scanner.close();
int exitCode = process.waitFor();
System.out.println("Process returned: " + exitCode);
apk , 1.
apk
ProcessBuilder apksync = new ProcessBuilder("adb","install","/home/geeky/Desktop/1.apk");
, , 141, , .apk . , APK , 700mb ( 500kb.apk ).
EDIT3: , apk, , apk /mnt/sdcard/test/ 1.apk.
Andy