Intent and Intentfilter
What is Intentfilter?
->intentfilter means "intent filter".
->intentfiltery is used to filter intent when implicit intent is used, i.e. "release" of the matching intent,
"Block" for mismatched intent.
Configure Intentfilter
Typically, in the Androidmanifest.xml file, the system components are configured under the node Intentfilter, for example:
Intentfilter, for example:
<activity
Android:name= "Com.example.intent.MainActivity"
Android:label= "@string/app_name" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
In some scenarios, you might use program code to configure Intentfilter, for example, in a broadcast receiver in an application
Filter criteria for Intentfilter
Intentfilter is valid for the following properties of intent:
(1) Action
(2) Catetory
(3) Data
Filter action
• Multiple actions can be added per Intentfilter.
• The value of the name attribute in each action node can be specified by the developer (typically the package name is prefixed), and on the same Android device, the value of the action should be
Does not conflict, therefore, the value is usually prefixed with the project package name.
Filter action
• Each intentfilter should specify at least one action, otherwise it will block all intent.
• If the intent object itself does not specify an action property, it will not participate in the matching checksum.
• Release if the Action property specified by the intent object matches any action in the Intentfilter.
Filter category
• Multiple category can be added per Intentfilter
• As with the action node, the value of the name attribute in the category node can be specified by the developer and should not
The conflict occurs.
• Developers can specify no category for intent objects, or multiple category.
· The Android system will inevitably add the default category for each intent object, namely:
. Android.intent.category.DEFAULT
In the filter rule, each category in the intent can be found in the Intentfilter, then released, otherwise it will be blocked, i.e.
The conditions for release are:
There is a default category in the Intentfilter;
Intentfilter in the category, compared to the category in the intent, only a lot, not less.
Filter data
• Multiple data can be added per Intentfilter
• Wildcard characters can be used when specifying MIME types in the Android:mimetype property, such as: text/*, video/*, and so on.
Filter data
• The full format of each URI is:
Scheme://host:port:/path
• The above properties are optional when configuring data in Intentfilter, but they are not independent
• about whether the URI matches:
• If only scheme is specified in Intentfilter, the URI of any scheme is matched, ignoring the host,port.path part;
• If Scheme,host is specified in Intentfilter, the URI of any of the same scheme and host matches, ignoring the path section
• If Scheme,host,port is specified in Intentfilter, then any of the same scheme and, Host,port URIs match, ignoring the path section
• If the full URI sections are specified in the Intentfilter, the URI that requires authentication must also match exactly
· Data filtering rules:
• If the intent does not specify a URI and mime, only if Intentfilter does not specify the URI and mime when it is released;
• If a URI is specified in intent but no MIME is specified and MIME cannot be inferred based on the URI, only if the Intentfilter
The same URI is specified and no MIME is specified for release;
• If the URI is not specified in the intent, but MIME is specified, only if Intentfilter does not specify a URI and specifies the same
MIME is released;
• If both URI and MIME are specified in intent, only the same URI and mime are specified in Intentfilter
No MIME is specified in the Intentfilter, but the MIME is inferred from the URI to release
Summarize:
· Intentfilter can specify action,category,data to verify the match, the matching intent will be released, otherwise it will be blocked.
• The approximate rules are as follows (commonly set configuration rules):
The action in the Action:intent object (up to 1) can be found in intentfileter;
• All the category in the Category:intent object can be found in the Intentfilter,
And the intent object must have
Android.intent.category,default this category
Intent and Intentfilter