Difference between GET_INTENT_FILTERS and MATCH_DEFAULT_ONLY when querying the packageManager to handle an intent

StackOverflow https://stackoverflow.com/questions/20506406

Question

I get different results when i used GET_INTENT_FILTERS and MATCH_DEFAULT_ONLY when i query the packageManager. Im trying to find the correct filter i need to set. Can somebody explain the difference?

final PackageManager mgr = mContext.getPackageManager();
List<ResolveInfo> list = mgr.queryIntentActivities(intent,
                PackageManager.GET_INTENT_FILTERS);
Was it helpful?

Solution

If you specify MATCH_DEFAULT_ONLY the call will return a ResolveInfo object for all activities that match the provided Intent. When performing the matching, Android will only consider activities that have CATEGORY=DEFAULT in their <intent-filter> definition in the manifest. This is the same matching behaviour as used when calling startActivity() on the Intent. If you do not specify this flag, the query will return all matching activities, even ones that do not contain CATEGORY=DEFAULT in their <intent-filter>. Of course, if the Intent that you pass to queryIntentActivities() already contains CATEGORY=DEFAULT, then the flag is not needed.

If you specify GET_INTENT_FILTERS, the resulting ResolveInfo objects will also contain the IntentFilter that was successfully matched. You can access this via ResolveInfo.filter.

These 2 flags are not mutually exclusive. MATCH_DEFAULT_ONLY controls how the matching is performed to determine which ResolveInfo objects to return. GET_INTENT_FILTERS controls what (additional) information is returned in the ResolveInfo objects themselves. If you want you can specify both flags like this MATCH_DEFAULT_ONLY | GET_INTENT_FILTERS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top