How to install APK automatically when the file download is complete (hosted on private)

Not possible. As some of those links point out, making an APK that automatically installs itself and deletes the original installer without any further user intervention is called malware.

You can write a program that will download and install arbitrary APKs if the user grants it the relevant permissions, but I'm yet to see a good implementation or documentation for this. Typically you can invoke the default system installer using code like this:

File apkFile = new File({path to APK});
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
    startActivity(intent);

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

The above code will install the myapkfile.apk. You just need to put this code in the onCreate() of the Activity.


Have you tried adding the below permission?

<uses-permission
    android:name="android.permission.INSTALL_PACKAGES" />

Add the above code to your manifest (especially when you are getting security exception).

You can refer to Install apps silently, with granted INSTALL_PACKAGES permission

Hope this works for you.