Use intent filter to respond to implicit intent

Source: Internet
Author: User

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:

 

Invalid action

Use 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.

 

CATEGORY category

The Android: Category attribute is used 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 follows:

 

❑ Alternative

As 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

Similar to alternative, 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.

 

❑ Default

Set 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.

 

Administrative home

Home 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.

 

❑ Launcher

This type is used to make an activity as the startup Item of the application.

 

❑ Data

The data tag allows you to specify the data matching that the component can act on. If your component can process multiple conditions, you can include multiple conditions. You can use any combination of the following attributes to specify the data supported by the component:

 

Using Android: Host

Specify a valid Host Name (for example, Com. Google ).

 

Using Android: mimetype

You can set the data types that the component can process. For example, <type android: value = "Vnd. Android. cursor. DIR/*"/> can match any android cursor.

 

Using Android: Path

Valid URI path value (for example,/transport/boats /).

 

Using Android: Port

Valid port on a specific host.

 

Using Android: Scheme

A special illustration (such as content or HTTP) is required ).

 

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 .)

 

<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>

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.