简体   繁体   English

Android Things:如何使用pm install -r从设备安装APK

[英]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 . 我正在尝试为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 到目前为止,我已经将.apk的新版本下载到/sdcard/download/app.apk ,也可以通过adb终端从那里安装它,例如

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 我也尝试这样打开外壳,但是这次我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? 是否可以从设备本身安装下载的apk? The general way with Intent.ACTION_VIEW doesn't work either. 使用Intent.ACTION_VIEW的常规方法也不起作用。 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. 但是,未经用户的明确许可,您无法安装.apks Not unless the device and your program are rooted. 除非设备和您的程序已植根。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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