How to use default Package Installer (Android) when trying to install an APK from another app?

Akh picture Akh · Aug 22, 2013 · Viewed 17.6k times · Source

I have been trying to install other apps from my app. I have downloaded the .apk from the server and I am firing an intent with the following content

Intent installIntent = new Intent(Intent.ACTION_INSTALL_PACKAGE);

installIntent.setData(Uri.parse("file:<apk file location>"));
installIntent.putExtra(Intent.EXTRA_INSTALLER_PACKAGE_NAME, DOWNLOADED_PACKAGE_NAME);
installIntent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
installIntent.putExtra(Intent.EXTRA_RETURN_RESULT, true);

startActivityForResult(installIntent, REQUEST_INSTALL); 
  • But I am stuck with setting the default installer while trying to install a package.
  • Following prompt is shown once my install intent is fired ask user to choose a default application to handle the intent which is not desired.
  • This prompt shouldn't be shown to the user.
  • The desired behavior is to start installing the package once download is complete like Google Play does.
  • Install Button clicked --> Download --> Ask Permission --> Install.

How to avoid this prompt?

This feature has been added since 4.2 ONLY.

enter image description here

Answer

Ricky picture Ricky · Jan 17, 2014

Problem Solved.

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setClassName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity");