[英]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.