1

I am trying to build an auto-updater for the Android Things app.apk. So far I have downloaded the new version of the .apk into the /sdcard/download/app.apk and I can also install it from there via the adb terminal e.g.

adb shell
pm install -r /sdcard/Download/app

Now I try to do the same via the device itself. Currently I have this

Process install = Runtime.getRuntime().exec("pm install -r /sdcard/Download/app");
install.waitFor();

But nothing happens. I tried to also open the shell like this, but this time I am getting Cannot run program "su": error=13, Permission denied

 Process install = Runtime.getRuntime().exec("su");
 DataOutputStream out = new DataOutputStream(install.getOutputStream());
 out.writeBytes("pm install -r /sdcard/Download/app");
 out.flush();

Is it possible at all to install the downloaded apk from the device itself? The general way with Intent.ACTION_VIEW doesn't work either. It blanks out and that's it. Nothing happens.

Murat Karagöz
  • 35,401
  • 16
  • 78
  • 107

2 Answers2

0

Use ADB command

adb install /path-of-your-apk/app.apk
Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
Vrushali Raut
  • 1,130
  • 1
  • 10
  • 20
0

You can easily launch an install prompt:

Intent promptInstall = new Intent(Intent.ACTION_VIEW)
    .setDataAndType(Uri.parse("file:///path/to/your.apk"), 
                    "application/vnd.android.package-archive");
startActivity(promptInstall); 

However, you cannot install .apks without user's explicit permission. Not unless the device and your program are rooted.

Mohammad Zarei
  • 1,773
  • 14
  • 33