在后台以编程方式安装 APK

编程入门 行业动态 更新时间:2024-10-26 00:27:39
本文介绍了在后台以编程方式安装 APK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个场景,我必须在后台下载 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-18 01:39:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/928103.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后台   方式   APK

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!