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

查看:113
本文介绍了在后台以编程方式安装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天全站免登陆