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);
If you specify
MATCH_DEFAULT_ONLY
the call will return aResolveInfo
object for all activities that match the providedIntent
. When performing the matching, Android will only consider activities that haveCATEGORY=DEFAULT
in their<intent-filter>
definition in the manifest. This is the same matching behaviour as used when callingstartActivity()
on theIntent
. If you do not specify this flag, the query will return all matching activities, even ones that do not containCATEGORY=DEFAULT
in their<intent-filter>
. Of course, if theIntent
that you pass toqueryIntentActivities()
already containsCATEGORY=DEFAULT
, then the flag is not needed.If you specify
GET_INTENT_FILTERS
, the resultingResolveInfo
objects will also contain theIntentFilter
that was successfully matched. You can access this viaResolveInfo.filter
.These 2 flags are not mutually exclusive.
MATCH_DEFAULT_ONLY
controls how the matching is performed to determine whichResolveInfo
objects to return.GET_INTENT_FILTERS
controls what (additional) information is returned in theResolveInfo
objects themselves. If you want you can specify both flags like thisMATCH_DEFAULT_ONLY | GET_INTENT_FILTERS