在后台以编程方式安装 APK [英] Installing APK programmatically in background

查看:36
本文介绍了在后台以编程方式安装 APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个场景,我必须在后台下载 apk 并安装它不向用户提示任何对话框.但是,当我尝试使用以下代码安装它时

I have scenario where I have to download apk in background and install it without prompting any dialog to user. However when I try to install it using below code

File file = new File(filename);
if(file.exists()){
    try {
        String command;
        command = "pm install -r " + filename;
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
        proc.waitFor();
        Config.debug("Apk installed");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

它要求超级用户访问.有没有办法不用超级用户安装apk并提示用户?

It ask for super user access. Is there any way to install apk without super user and prompting to user?

推荐答案

有没有办法在没有超级用户的情况下安装apk并提示用户?

Is there any way to install apk without super user and prompting to user?

幸运的是,没有,出于明显的安全原因.

Fortunately, no, for obvious security reasons.

更新:一个例外是在 Android 5.0+ 设备上,如果您使用的是设备所有者系统,我认为有一些 API 可用于安装可用于设备所有者应用程序的软件包.我还没有玩过这些,目前还不清楚它们是否能满足您的需求.

UPDATE: One exception is on Android 5.0+ devices, if you are using the device owner system, I think there are some APIs for installing packages that are available to device owner apps. I haven't played with these yet, and it is unclear whether they would meet your needs anyway.

我问这个是因为我拥有的用户群,以前从未使用过应用程序或设备

I am asking this becoz the user base that I have, have never used app or device before

然后要么不给他们这项技术,要么教他们如何使用这项技术.

Then either do not give them this technology or teach them how to use this technology.

这篇关于在后台以编程方式安装 APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆