Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PackageInstallerActivity not found on Android M developer preview

I have a feature to be implemented: install an apk programmatically. Code I'm using:

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);

The callingIntent contains an apk from another service.

On Android 6.0 (MPA44G, Nexus 5), this intent 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 is working fine.

Has Google completely removed the PackageInstallerActivity? Is there any workaround to programmatically install an apk specifically on Android 6.0?

Reference: Issue 3017: Unable to find explicit activity class com.android.packageinstaller.PackageInstallerActivity

like image 627
Song Avatar asked Aug 25 '15 18:08

Song


People also ask

Why is my Package Installer not working?

Settings -> Apps -> All -> Package Installer Clear Cache & Data, Force Stop, reboot. If this doesn't work repeat, but reboot into recovery and wipe the cache partition. Still having issues try AppInstaller.

What is a Google Android package installer?

android.content.pm.PackageInstaller. Offers the ability to install, upgrade, and remove applications on the device. This includes support for apps packaged either as a single "monolithic" APK, or apps packaged as multiple "split" APKs. An app is delivered for installation through a PackageInstaller.

What is Package Installer APK?

Package Installer is the service that runs in the background when you install, update, or uninstall apps on your Android device. Put simply, it's an app that installs and uninstalls other apps.


1 Answers

I got the answer. Intent.ACTION_INSTALL_PACKAGE is a better choice. If your app is registered as a package installer, use the sample code below to bypass a chooser 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);  
like image 171
Song Avatar answered Sep 28 '22 01:09

Song