PackageInstallerActivity not found on Android M preview

I have a function that will be implemented: programmatically install apk. The code I'm using is:

ComponentName comp = new ComponentName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity"); Intent newIntent = new Intent(callingIntent); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); newIntent.setComponent(comp); 

CallIntent contains apk from another service.

In Android 6.0 (MPA44G, Nexus 5) this intention is crashing. Logcat:

 08-20 14:58:56.127 26222 26222 E AndroidRuntime: Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.android.packageinstaller/com.android.packageinstaller.PackageInstallerActivity}; have you declared this activity in your AndroidManifest.xml? 

On Lollipop devices, the above code works fine.

Has Google Completely Deleted PackageInstallerActivity? Is there any way around the apk software installation specifically for Android 6.0?

Ref: Issue 3017: Cannot find explicit activity class com.android.packageinstaller.PackageInstallerActivity

+6
source share
5 answers

I got an answer. Intent.ACTION_INSTALL_PACKAGE is the best choice. If your application is registered as a package installer, use the sample code below to bypass the selection dialog:

 intent = new Intent(Intent.ACTION_INSTALL_PACKAGE); intent.setData(Uri.fromFile(file)); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

If you want to use the standard package installer, use the following code:

 File apkFile = new File(apkFileString); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); mContext.startActivity(intent); 
+2
source

As you noticed, the package path was incorrect and without specifying it, it will get rid of the failure. Now we have

 API <= 22 com.android.packageinstaller API >= 23 com.google.android.packageinstaller 

You can find any path to the system application on the device with adb. An example of how I am looking for a new package installer on Nexus 5X is as follows.

 $ adb shell 'pm list packages -f install' package:/data/app/android.autoinstalls.config.google.nexus-1/base.apk=android.autoinstalls.config.google.nexus package:/system/app/CertInstaller/CertInstaller.apk=com.android.certinstaller package:/system/priv-app/GooglePackageInstaller/GooglePackageInstaller.apk=com.google.android.packageinstaller 
+2
source

In addition to @Adam Wigren's answer:
In Android 6, the package name has been changed, but not activity

 ComponentName comp; if(android.os.Build.VERSION.SDK_INT < 23){ comp = new ComponentName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity"); }else{ comp = new ComponentName("com.google.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity"); } Intent newIntent = new Intent(callingIntent); newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); newIntent.setComponent(comp); 
0
source

You can simply open the apk file in android6.0. see demo code

0
source

To avoid: ActivityNotFoundException with Intent.ACTION_INSTALL_PACKAGE

  ComponentName comp; File apkFile = new File(apkFileString); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive"); if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1/*23*/){ comp = new ComponentName("com.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity"); }else{ comp = new ComponentName("com.google.android.packageinstaller", "com.android.packageinstaller.PackageInstallerActivity"); } intent.setComponent(comp); startActivity(intent); 
0
source

All Articles