getPacketManager()。resolveActivity(...) - 仅对系统应用程序失败

时间:2015-03-28 16:53:10

标签: android android-intent android-package-managers

当我用system packageNames调用resolveActivity()函数时,我收到以下异常:

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)

此例外可通过以下方式重现:

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

我使用SDK 21和Build Tools" 21.1.1"

1 个答案:

答案 0 :(得分:4)

要解决此问题,我使用以下内容而不是空构造函数初始化Intent:

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