从URL安装APKURL、APK

2023-09-06 22:07:10 作者:戒情不戒酒

我尝试从为URL安装APK,这是我的code:

I try to install an apk from an URl, this is my code:

 Intent promptInstall = new Intent(android.content.Intent.ACTION_VIEW);
    promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    promptInstall.setDataAndType(Uri.parse("http://10.0.2.2:8081/MyAPPStore/apk/Teflouki.apk"), "application/vnd.android.package-archive" );

       startActivity(promptInstall);

不过,我有这样的问题:

But i have this problem:

   05-10 15:09:29.511: ERROR/AndroidRuntime(1668): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://10.0.2.2:8081/MyAPPStore/apk/Teflouki.apk typ=application/vnd.android.package-archive flg=0x10000000 }

在此先感谢

推荐答案

这将不利于如果应用程序不可用在mearketplace,但在情况下,它是:

This won't help if the app is not available on the mearketplace, but in case it is:

Uri marketUri = Uri.parse("market://search?q=pname:com.appmaker.tefloukipackage");
                                        Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
                                        try {
                                            context.startActivity(marketIntent);
                                        } catch (ActivityNotFoundException ex) {
                                            showAlertDialog(context, "Error", "Could not launch the market application.", true, null);
                                        }