I`m interested in knowing if it is possible to programmatically install a dynamically downloaded apk from a custom Android application.
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);
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.
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.