简体   繁体   中英

Android Things: How to install apk from device with pm install -r

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 eg

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.

使用ADB命令

adb install /path-of-your-apk/app.apk

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM