install apk from url

8

I am trying to install an APK from a 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 }

Thanks in advance.

android
asked on Stack Overflow May 10, 2011 by lady android • edited Sep 24, 2019 by stkent

3 Answers

4

You should download xxx.apk in storage before install by:

Intent promptInstall = new Intent(android.content.Intent.ACTION_VIEW);
promptInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
promptInstall.setDataAndType(Uri.parse("storage/xxx.apk"), "application/vnd.android.package-archive" );
startActivity(promptInstall);
answered on Stack Overflow Mar 17, 2016 by on the coming • edited Apr 15, 2016 by Remy Lebeau
2

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);
}
answered on Stack Overflow May 10, 2011 by kellogs • edited Sep 24, 2019 by stkent
0

Try looking here first: Android: install .apk programmatically

It might be a better idea to download the apk first then install it.

answered on Stack Overflow May 10, 2011 by Nelson Ramirez • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0