简体   繁体   English

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

[英]How to download and install another Android app on android device

Is there way to be able to download and install another android app from a URL programmatically? 有没有办法能够以编程方式从URL下载并安装另一个Android应用程序? I tried following 我尝试了以下

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);

but it gave me error 但这给了我错误

   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 }

Am I missing some permissions? 我缺少一些权限吗? I tried giving 我尝试给

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

but that doesn't let me compile in eclipse 但这不能让我在日食中编译

Can someone please help and let me know if I am doing soemthing wrong 有人可以帮忙吗,让我知道我做错了什么

Thanks Monty 谢谢蒙蒂

There's no way you can install an app without the user acknowledgement. 没有用户确认,您无法安装应用程序。

Once you have donwloaded the apk, you should use ACTION_INSTALL_PACKAGE instead of ACTION_VIEW 下载完APK后,您应该使用ACTION_INSTALL_PACKAGE而不是ACTION_VIEW

From the documentation: 从文档中:

Activity Action: Launch application installer. 活动操作:启动应用程序安装程序。

Input: The data must be a content: or file: URI at which the application can be retrieved. 输入:数据必须是内容:或文件:可在其中检索应用程序的URI。 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. 从JELLY_BEAN_MR1开始,您还可以使用“ package:”为当前用户安装已经为另一个用户安装的应用程序。 You can optionally supply EXTRA_INSTALLER_PACKAGE_NAME, EXTRA_NOT_UNKNOWN_SOURCE, EXTRA_ALLOW_REPLACE, and EXTRA_RETURN_RESULT. 您可以选择提供EXTRA_INSTALLER_PACKAGE_NAME,EXTRA_NOT_UNKNOWN_SOURCE,EXTRA_ALLOW_REPLACE和EXTRA_RETURN_RESULT。

Output: If EXTRA_RETURN_RESULT, returns whether the install succeeded. 输出:如果为EXTRA_RETURN_RESULT,则返回安装是否成功。

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(pass the url to downlad app)); Intent browserIntent =新的Intent(Intent.ACTION_VIEW,Uri.parse(将网址传递给下载的应用));

    startActivity(browserIntent);

Rest provide the persimmion of internet and storage in manifest. 其余的以清单形式提供Internet和存储的权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从另一个Android应用下载并安装Android应用 - Download and install android app from another android app 禁止为特定的Android版本或设备下载/安装App - Disable download / install of App for a specific Android Version or Device 科尔多瓦如何将应用程序直接安装到Android设备上? - Cordova how to install app directly to Android device? 是否可以通过共享 apk 文件将开发中的应用程序安装到另一个 android 设备? - Is it possible to install developing app to another android device by sharing the apk file? 在设备上安装 Android App Bundle - Install Android App Bundle on device 如何强制将我的Android应用安装在移动设备上而不是下载 - How to force my android app to be installed in mobile device instead of download Android-以编程方式下载其他应用 - Android - download another app programmatically 如何创建一个可检测设备所有下载内容的Android应用? - How to create an android app that detects all of the device's download? Android应用可以安装另一个Android应用吗? - Can an Android app install another android app? Android:可以通过使用设备管理来下载和安装应用程序而无需获得用户许可 - Android : Is it possible to download and install app without getting user permission by using Device Administration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM