Ari
Ari

Reputation: 1470

getPacketManager().resolveActivity(...) - Fails only with system applications

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 reproduceable via:

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

I use SDK 21 and Build Tools "21.1.1"

Upvotes: 2

Views: 992

Answers (1)

Ari
Ari

Reputation: 1470

To fix this problem I initialized Intent with the following instead of the empty constructor:

    Intent intent = new Intent(Intent.ACTION_MAIN, null);

Upvotes: 4

Related Questions