The third lesson IntentFilter matching rules

<intent-filter>
    <action android:name="com.syy.note.a"/>
    <action android:name="com.syy.note.b"/>
    <category android:name="com.syy.category.c"/>
    <category android:name="com.syy.category.d"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="text/plain"/>
</intent-filter>

action

Matching rules: there must be, and must match one of the action attributes in the filter.

category

Matching rules:

It can be absent, if not, it will match "android.intent.catetory.DEFAULT", so when configuring <intent-filter>, the category attribute must have "android.intent.catetory.DEFAULT";

If there is, it must match one of the catetory attributes in the filter.

data

Matching rules: must have, and must match the data attribute in the filter, the data syntax is as follows:

<data android:scheme="string"
    android:host="string"
    android:port="string"
    android:path="string"
    android:pathPattern="string"
    android:pathPrefix="string"
    android:mimeType="string"  />

Data consists of two parts: mimeType and URI. mimeType refers to the media type, such as image/jpeg, vidio/*, etc. The URI structure:

<scheme>://<host>:<port>/[<path>|<pathPrefix>|<pathPattern>]

Specify data for the intent through the setDataAndType method:

intent.setDataAndType(Uri.parse("file://abc"),"image/png");

In summary

We can give the intent-filter at the beginning of the article the Intent that matches it:

Intent intent = new Intent("com.syy.note.a");
intent.addCategory("com.syy.category.c");
intent.setDataAndType(Uri.parse("file://abc"),"text/plain");
startActivity(intent);

 

 

 

Guess you like

Origin blog.csdn.net/wishxiaozhu/article/details/114603697