gpt4 book ai didi

android - 如何在安卓设备上下载并安装另一个安卓应用

转载 作者:行者123 更新时间:2023-11-29 01:57:54 25 4
gpt4 key购买 nike

有没有办法以编程方式从 URL 下载和安装另一个 Android 应用程序?我试着跟随

Intent promptInstall = new Intent(Intent.ACTION_VIEW);

promptInstall.setDataAndType(Uri.fromFiledwfile), "application/vnd.android.package_archive");
promptInstall.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

startActivity(promptInstall);

但它给了我错误

   java.lang.RuntimeException: Unable to start activity 
ComponentInfo{com.example.test/com.example.test.MainActivity}:

android.content.ActivityNotFoundException: No Activity found to handle Intent {

act=android.intent.action.VIEW dat=file:///mnt/sdcard/download/Demo.apk

typ=application/vnd.android.package_archive flg=0x10000000 }

我是否缺少某些权限?我试着给

<uses-permission android:name="android.permission.INSTALL_PACKAGES"  />

但这不允许我在 eclipse 中编译

如果我做错了什么,有人可以帮忙告诉我吗

谢谢蒙蒂

最佳答案

没有用户确认,您无法安装应用。

一旦你下载了 apk,你应该使用 ACTION_INSTALL_PACKAGE而不是 ACTION_VIEW

来自文档:

Activity Action: Launch application installer.

Input: The data must be a content: or file: URI at which the application can be retrieved. As of JELLY_BEAN_MR1, you can also use "package:" to install an application for the current user that is already installed for another user. You can optionally supply EXTRA_INSTALLER_PACKAGE_NAME, EXTRA_NOT_UNKNOWN_SOURCE, EXTRA_ALLOW_REPLACE, and EXTRA_RETURN_RESULT.

Output: If EXTRA_RETURN_RESULT, returns whether the install succeeded.

关于android - 如何在安卓设备上下载并安装另一个安卓应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14168670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com