Home > Enterprise >  android why the ResolveInfo got from resolveActivity() is different than from queryIntentActivities(
android why the ResolveInfo got from resolveActivity() is different than from queryIntentActivities(

Time:11-03

When looking at the ResolveInfo return from resolveActivity() and queryIntentActivities(),

why the ResolveInfo is different from these two calls for the same intent?

the viewIntent is Intent(Intent.ACTION_VIEW, Uri.parse(deeplinkData), and the one returned from resolveActivity has unrelated packagename/name:

ResolveInfo info = pm.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);

        System.out.println("    111 resolveActivity(), info.activityInfo.packageName:  " info.activityInfo.packageName ",\ninfo.activityInfo.name: " info.activityInfo.name);

it has log:

    111 resolveActivity(), info.activityInfo.packageName: android, 

info.activityInfo.name: com.android.internal.app.ResolverActivity

where using queryIntentActivities

List<ResolveInfo> resInfo = pm.queryIntentActivities(viewIntent, 0);
if (!resInfo.isEmpty()){
            for (ResolveInfo info : resInfo) {

                System.out.println("    queryIntentActivities(), info.activityInfo.packageName: "  (info.activityInfo.packageName));
                System.out.println("        queryIntentActivities(), info.activityInfo.name: "  (info.activityInfo.name));

                ......
            }
        }

has log:

    queryIntentActivities(), info.activityInfo.packageName: com.client.android.debug
        queryIntentActivities(), info.activityInfo.name: com.client.android.NewsActivity
    queryIntentActivities(), info.activityInfo.packageName: com.android.chrome
        queryIntentActivities(), info.activityInfo.name: com.google.android.apps.chrome.IntentDispatcher

CodePudding user response:

resolveActivity() returns the component that would be started if you call startActivity(). That will be:

  • null if there is no match or you are not set up package visibility rules on Android 11
  • the activity that would be started from some app, if there is exactly one match or if the user chose a default
  • the chooser activity, if there are 2 matches and there is no default

In your case, you are getting the chooser activity (com.android.internal.app.ResolverActivity).

  • Related