问题描述
我遇到必须在后台下载apk并进行安装的情况而不提示任何对话框给用户.但是,当我尝试使用以下代码进行安装
I have scenario where I have to download apk in background and install itwithout 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?
推荐答案
幸运的是,出于明显的安全原因.
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.
然后要么不给他们这项技术,要么不教他们如何使用这项技术.
Then either do not give them this technology or teach them how to use this technology.
这篇关于在后台以编程方式安装APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!