Android Activity intent-flilter filtering mechanism
In Android, if one app (APP1) wants to call an Activity (Activity2) of another app (APP2 ), the parameters set for Intent can be declared in the configuration file via Activiy2 Property verification can be successfully called to the Activity. Tags can be used for verification: Action verification, Category verification, and Data verification. Action verification must be declared.
Action Verification:
One Activity can declare multiple actions. If one Activity passes verification, it passes verification. If Activity2 declares the following three actions:
…………
Other applications can call Activity2 by setting the Action Method for Intent (if other applications in the system also have the same Action, the list will be provided for the user to choose from), such:
Intent intent=new Intent();intent.setAction("ACTION1");startActivity(intent);
Category Verification:
Activity2 You can also declare multiple Category verifications, as shown below (the DEFAULT one is automatically added by the system and will still exist if it is not declared in time ):
In other applications, you can add a Category for the Intent. When all the added Category is declared in Activity2, it passes verification. The following Intent can pass Verification:
Intent intent=new Intent(); intent.setAction("ACTION1"); intent.addCategory("CATEGORY1"); intent.addCategory("CATEGORY3"); startActivity(intent);
Data Verification:
Data verification is complex. You can verify the Mime Type and Uri set in Intent. Mime Type can specify the Type of the processed resource. For example, "audio/*" indicates all audio resources. Set MimeType:
The called Intent can set the Mime Type through setType () or setTypeAndNormalize,
Intent intent=new Intent(); intent.setAction("ACTION1"); intent.setType("audio/*"); // intent.setTypeAndNormalize("audio/*"); startActivity(intent);
Uri has a wide range of URLs in the format of scheme: // host: port/path. scheme indicates the Protocol identity, such as http, host indicates the IP address, domain name, and port indicates the port number, path is the path. In Of For example, if scheme is set, host is not set, and port is directly set, the port setting will be ignored, it is the same as port not set. When setting the path, you can use the path to set the entire path, or you can use pathPrefix to set the path starting with, or you can use pathPattern to set the path with the wildcard "*" and ". * ", where" * "is the same as" * "in the regular expression, indicating that the first character is 0 or any number, and". "represents any character. If "abc * d" matches "abcccd" and "abcd", "abc. * d" matches "abced" and "abcfd. In In Set the Uri format as follows:
The corresponding Intent call can be as follows:
Intent intent = new Intent (); intent. setAction ("ACTION1"); Uri uri = Uri. parse ("http://www.google.com: 8080/abc. jsp "); // match path // Uri uri = Uri. parse ("http://www.google.com: 8080/index. jsp "); // match pathPrefix // Uri uri = Uri. parse ("http://www.google.com: 8080/idexn"); // match pathPattern intent. setData (uri); startActivity (intent );
However, it should be noted that the setData () method and setType () method of Intent will overwrite each other. That is to say, if setType () is used to set the Mime Type, then setData () is used () if Uri is set, the previously set MimeType will be cleared, and vice versa. The following is the source code of the setData () method, which is easy to understand:
public Intent setData(Uri data) { mData = data; mType = null; return this;}
If an Activity's Of If both mimeType and Uri are set, you need to use the setDataAndType (Uridata, String type) of Intent to set it.
To sum up, if an Activity Declare Action verification, Category, and Data verification. To call this Activity implicitly, another application must set the correct parameters for Intent. This Activity can be called only when all parameters are verified. Note that the exported8 attribute of the called Activity must be set to true (default) to be called by other applications.