Android development-intent-filter attributes

Source: Internet
Author: User

To respect the author, put the author link at the beginning.

From: http://hi.baidu.com/lvqiyong/blog/item/7645152733f3af7435a80ff1.html

If an intent request executes an action on a piece of data, how does Android know which application (and component) can respond to this request? Intent filter is used to register activity, service, and broadcast referers to execute an action on certain data. Using intent filter, app components tell android that they can provide services for the action requests of other program components, including the components of the same program, local or third-party applications. To register an application component as an intent processor, add an intent-filter tag to the component's manifest node. Use the following tags (associated attributes) in the intent filter node to specify the actions, types, and data supported by the component: 1. Test the action.
The <intent-filter> element can contain sub-elements <action>, for example:
View Source print?

    < intent-filter > < action android:name="com.example.project.SHOW_CURRENT"/> < action android:name="com.example.project.SHOW_RECENT"/> < action android:name="com.example.project.SHOW_PENDING"/></ intent-filter>
    A <intent-filter> element must contain at least one <action>. Otherwise, no intent request can match the <intent-filter> element. If the action requested by intent matches a <action> in <intent-filter>, the intent passes the <intent-filter> action test. If the action type is not specified in the intent request or <intent-filter>, the following two cases may occur.
    (1) If <intent-filter> does not contain any action type, no intent request can match <intent-filter>;
    (2) If the intent request does not set the action type, as long as <intent-filter> contains the action type, this intent request will pass the <intent-filter> behavior test smoothly.
    2. Category Test
    The <intent-filter> element can contain <Category> sub-elements, such:
    View Source print?
    < intent-filter . . . >  < category android:name="android.Intent.Category.DEFAULT"/>  < category android:name="android.Intent.Category.BROWSABLE"/></ intent-filter>
    The intent request will pass the test only when all the category in the intent request matches the <Category> of an intentfilter in the component, the redundant <Category> declaration in intentfilter does not cause a matching failure. An intentfilter that does not specify any category for testing only matches intent requests that do not set a category.
    3. Data Testing
    The description of data in <intent-filter> is as follows:
    View Source print?
    < intent-filter . . . > < data android:type="video/mpeg" android:scheme="http". . . /> < data android:type="audio/mpeg" android:scheme="http". . . /></ intent-filter>
    The <DATA> element specifies the data Uri and Data Type of the intent request to be accepted. The URI is divided into three parts for matching: Scheme, authority, and path. The URI data type and scheme of the inteat request set with setdata () must be consistent with the one specified in intentfilter. If authority or path is also specified in intentfilter, they also need to match to pass the test.
Action uses the Android: Name feature to specify the action name for the response. Action names must be unique strings. Therefore, a good habit is to use a naming system based on Java packages. Categorcategory uses the Android: Category attribute to specify the environment in which actions are responded. Each intent filter tag can contain multiple category tags. You can specify a custom type or use the standard value provided by Android, as shown in the following figure: using alternative what you will see later in this chapter, the purpose of an intent filter is to use actions to help fill in the context menu. The alternative type is specified. In a data type project, the default action can be replaced. For example, when a contact's default action is viewed, it may be edited or deleted. ❑ Selected_alternative is similar to alternative, but alternative always points to a single action using the intent resolution described below. Selected_alternative is used when a list of possibilities is required. ❑ Browsable specifies the action in the browser. When intent is triggered in the browser, it is specified as a browsable type. Define default sets this type to make the component the default action of data defined in the intent filter. This is also necessary for activities started with explicit intent. ❑ Gadget: by setting the gadget type, you can specify that this activity can be embedded into other activities to allow. ❑ Homehome activity is the first activity displayed when the device starts (login screen. By specifying the intent filter as the home type without specifying the action, you are setting it as an alternative to the local home screen. The launch launcher uses this type to enable an activity as the startup Item of the application. The ❑ datadata tag allows you to specify the data matching that the component can act on. If your component can process multiple conditions, you can contain multiple conditions. You can use any combination of the following attributes to specify the data supported by the component: Allow Android: host to specify a valid Host Name (for example, Com. Google ). Customized Android: mimetype allows you to set the data types that can be processed by components. For example, <type android: value = "Vnd. Android. cursor. DIR/*"/> can match any android cursor. Valid Android: path valid URI path value (for example,/transport/boats /). Using Android: port a valid port on a specific host. Upload Android: scheme requires a special icon (such as content or HTTP ). The following code snippet shows how to configure the intent filter of an activity to execute the show_damage action with the default or replaceable action identity under specific data. (The next section describes how to create an earthquake .) Java code
  1. <activity android:name=".EarthquakeDamageViewer" android:label="View Damage"> <intent-filter>  <action    android:name="com.paad.earthquake.intent.action.SHOW_DAMAGE">  </action>  <category android:name="android.intent.category.DEFAULT"/>  <category android:name="android.intent.category.ALTERNATIVE_SELECTED" />  <data android:mimeType="vnd.earthquake.cursor.item/*"/> </intent-filter>  </activity> 

    How can I find relevant information? I will continue to complete it. I also hope you can share more with me ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.