Android : Nullpointer Exception with getPacketManager().resolveActivity Only with system applications

on Saturday, March 28, 2015


I retrieve all installed applications via the following code:



final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List < ResolveInfo > pkgAppsList = context.getPackageManager().queryIntentActivities(mainIntent, 0);


I am using SDK 21 and Build Tools "21.1.1"


When i call the resolveActivity() function with system packageNames i receive the following exception:



java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.getHost()' on a null object reference
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1493)
at android.content.pm.IPackageManager$Stub$Proxy.resolveIntent(IPackageManager.java:2513)
at android.app.ApplicationPackageManager.resolveActivityAsUser(ApplicationPackageManager.java:545)
at android.app.ApplicationPackageManager.resolveActivity(ApplicationPackageManager.java:539)
at com.github.aayvazyan.polyse.util.APKInfo.getResolveInfo(APKInfo.java:87)


This exception is reproducable via:



Intent intent = new Intent();
intent.setPackage("com.google.android.calendar");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ResolveInfo result = getPackageManager().resolveActivity(intent, 0);

0 comments:

Post a Comment