Install Application programmatically on Android


Question

I`m interested in knowing if it is possible to programmatically install a dynamically downloaded apk from a custom Android application.

1
197
5/10/2013 12:41:14 AM

Accepted Answer

You can easily launch a play store link or an install prompt:

Intent promptInstall = new Intent(Intent.ACTION_VIEW)
    .setDataAndType(Uri.parse("content:///path/to/your.apk"), 
                    "application/vnd.android.package-archive");
startActivity(promptInstall); 

or

Intent goToMarket = new Intent(Intent.ACTION_VIEW)
    .setData(Uri.parse("https://play.google.com/store/apps/details?id=com.package.name"));
startActivity(goToMarket);

However, you cannot install .apks without user's explicit permission; not unless the device and your program is rooted.

232
4/11/2019 11:27:39 AM

File file = new File(dir, "App.apk");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");
startActivity(intent);

I had the same problem and after several attempts, it worked out for me this way. I don't know why, but setting data and type separately screwed up my intent.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon