Four important attributes in intent--action, Data, Category, Extras

Source: Internet
Author: User

Four important attributes in intent--action, Data, Category, Extras 

Intent as a link between the activity, its role is not only limited to simple data transmission. Through its own properties, it is easy to complete a lot of more complex operations. For example, call the dialing function directly, automatically call the appropriate program to open different types of files and so on. And so on, you can do this by setting the intent property.

Intent mainly has the following four important attributes, respectively:

The value of the Action:action property is a string that represents a series of commonly used actions that have been defined in the system. Set through the Setaction () method or in the manifest file androidmanifest.xml. Defaults to: Default.

Data:data is typically the operation data defined by the URI format. For example: tel://. Set by the SetData () method.

The Category:category property is used to specify the environment in which the current action (action) is executed . Set through the Addcategory () method or in the manifest file androidmanifest.xml. The default is: Category_default.

The Extras:extras property is primarily used to pass the additional data required by the target component . Set by the Putextras () method.

The common values for each of the four properties are as follows:

  Action:

action_main:android Application 's entrance, each Android app must and can contain only one ACTION declaration of this type .

Action_view: The system displays data through the registered corresponding application according to the different data types .

Action_edit: The system edits the data according to the different data types through the registered corresponding application .

Action_dial: Opens the system's default dialer, and automatically enters this number in the dialer if the phone number is set in data .

Action_call: Direct call to the number in data .

Action_answer: Answer the call .

Action_send: The user specifies the sending method for the data send Operation .

Action_sendto: According to different data types, the system sends the data via the registered correspondence application .

The action_boot_completed:android system emits a broadcast with this action (broadcast) after it has been started.

A broadcast (broadcast) with this action is issued after the time of the action_time_changed:android system has changed.

A broadcast (broadcast) with this action is issued after the action_package_added:android system has installed a new application.

A broadcast (broadcast) with this action is issued after a change in the existing application in the Action_package_changed:android system, such as applying an update operation.

Action_package_removed: A broadcast (broadcast) with this action is issued after uninstalling an existing application of the Android system.

Category:

The default mode of execution in the category_default:android system is performed according to the execution of normal activity .

Category_home: Sets the component as the HOME Activity.

Category_preference: Set the component to PREFERENCE.

Category_launcher: Sets the component to be the highest priority activity in the current application launcher, typically used with ingress Action_main .

Category_browsable: Setting this component can be started using the browser .

Category_gadget: Setting this component can be embedded into another activity .

Extras:

EXTRA_BCC: An array of strings that hold the message's secret address.

EXTRA_CC: An array of strings that hold the e-mail cc addresses .

Extra_email: An array of strings that hold the e-mail address .

Extra_subject: Holds the message subject string .

Extra_text: Store the contents of the message .

Extra_key_event: the button that triggers intent is stored as a KeyEvent object .

Extra_phone_number: The phone number when the call to Action_call is stored .

Data:

tel://: The Number data format followed by the phone number.

MAILTO://: The message data format, followed by the mail recipient address .

SMSTO://: Short data format followed by SMS receiving number .

CONTENT://: The content data format, followed by what needs to be read.

file://: File data format followed by file path .

Market://search?q=pname:pkgname: Market data format, search for apps with the package name Pkgname in Google markets .

Geo://latitude,longitude: The latitude and Longitude data format that displays the location specified by the latitude and longitude on the map .

The actual purpose of specifying the Data property in Intent-filter is to require that data in the received intent be compliant with the data property specified in Intent-filter, so that the role of the reverse-qualified intent is achieved.

For example: In Androidmanifest.xml, make the following settings:

[HTML]View Plaincopy
  1. <activity android:name=". Testactivity ">
  2. <intent-filter>
  3. <action android:name="com.jony.test"/>
  4. <data android:scheme="file"/>
  5. </intent-filter>
  6. </activity>

The intent that initiates the activity must be set up as follows:

[Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Uri uri = uri.parse ("File://com.android.test:520/mnt/sdcard");
    3. Intent.setdata (URI);

Data attribute parsing: Android:scheme, Android:host, Android:port, Android:path, Android:mimetype

The first four properties of data form part of the URI, MimeType sets the type of the data

The URI model consisting of the data element is as follows:

Scheme://host:port/path

To illustrate:

URI File://com.android.jony.test:520/mnt/sdcard

Scheme-->file:

Host-->com.android.jony.test

port-->520

Path-->mnt/sdcard

Where host and port are URI authority, if no specified host,port will be ignored

The properties of data are not independent, and the properties of data form the entire component of the URI. To make authority (host and port) meaningful, scheme must be specified and scheme and authority (host and port) must be meaningful to make path meaningful.

Uri and Intent-filter match:

In intent, the URI and the intent-filter are compared only partially:

(1) When only scheme is set in Intent-filter, only the scheme portion of the URI is compared;

(2) When only scheme and authority are set in Intent-filter, only scheme and authority in the URI are matched;

(3) When scheme, authority, and path are set in Intent-filter, only the scheme, authority, path in the URI will be matched, (path can be matched using wildcard characters)

(4) When MimeType is set in Intent-filter, data type matching is also performed.

Summarize:

(1) In Androidmainfest.xml each activity has been explained--intent-filter,intent-filter the need to receive what kind of intent, When the sent intent and intent-filter are defined in accordance with the corresponding, it will initiate the appropriate activity;

(2) When there are multiple activity to match the sent intent, the Android system will list all the activity that satisfies intent, the user can choose to carry on the related operation;

(3) In an activity Intent-filter can have multiple action, multiple category, multiple data, so there are many combinations to match intent. Note: If multiple intent are matched in an activity, it is recommended to use multiple Intent-filter to match the intent. Guess: This should improve the intent matching speed.

(4) The Data property, which is a reverse-throttling intent operation, requires that intent's data must be one of the claims in Intent-filter (should be set in one intent-filter). Note: If you want to start the target activity, but the specified data datatype does not match the data type in activity, it will cause a activitynotfoundexception exception.

Four important attributes in intent--action, Data, Category, Extras

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.