getPacketManager().resolveActivity(...) - 仅在系统应用程序中失败
getPacketManager().resolveActivity(...) - Fails only with system applications
当我使用系统 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 和构建工具“21.1.1”
为了解决这个问题,我使用以下而不是空构造函数初始化了 Intent:
Intent intent = new Intent(Intent.ACTION_MAIN, null);
当我使用系统 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 和构建工具“21.1.1”
为了解决这个问题,我使用以下而不是空构造函数初始化了 Intent:
Intent intent = new Intent(Intent.ACTION_MAIN, null);