Description of Intent attributes 2. Action, Category, and intentcategory

Source: Internet
Author: User

Description of Intent attributes 2. Action, Category, and intentcategory

First look:

1. Action: actions that can be executed by the activity

This identifier indicates the actions that the activity can perform. If any of the actions listed in <intent-filter> matches the values when the intent action is passed implicitly, it indicates that this activity can fulfill the intent of this intent and activate it!

Common actions are as follows:

ACTION_CALL activity starts a call.

ACTION_EDIT activity displays edited data.

ACTION_MAIN activity is started as the first Activity in the Task.

ACTION_SYNC activity synchronizes data on mobile phones and data servers.

ACTION_BATTERY_LOW broadcast comment er indicates that the battery is too low.

ACTION_HEADSET_PLUG broadcast receiver er plug-in headset warning

The screen of ACTION_SCREEN_ON broadcast receiver er is highlighted with a warning.

ACTION_TIMEZONE_CHANGED broadcast receiver Time Zone change warning.

Two principles:

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 any <action> in <intent-filter>, then the Intent can activate the activity (provided that all items except action must pass ).

Two notes:

If the Action type is not specified in the Intent request or <intent-filter>, the following two cases may occur. If <intent-filter> does not contain any Action type, no Intent request can match <intent-filter>. If the Action type is not set in the Intent request, as long as <intent-filter> contains the Action type, this Intent request will pass the <intent-filter> behavior test smoothly.

2. Category: Specifies the stage in which the current Action is executed.

That is, the environment in which the activity can be activated. It does not belong to this environment and cannot be activated.

Common Category attributes are as follows:

CATEGORY_DEFAULT: the default execution method in the Android system. Indicates that all intent can activate it.

CATEGORY_HOME: set this component as Home Activity.

CATEGORY_PREFERENCE: set this component to Preference.

CATEGORY_LAUNCHER: set this component to the Activity with the highest priority in the current application launcher. It is usually used with the entry ACTION_MAIN.

CATEGORY_BROWSABLE: set this component to be started in a browser. Indicates that the activity can only be used to browse webpages.

CATEGORY_GADGET: set this component to be embedded in another Activity.

Note: If the activity is to be activated by using the implicit intent method, no category settings are available, including at least one android. intent. category. DEFAULT.

Appendix 3 Intent call common system component Methods
// Call the browser Uri webViewUri = Uri. parse ("http://blog.csdn.net/zuolongsnail"); Intent intent = new Intent (Intent. ACTION_VIEW, webViewUri); // call the map Uri mapUri = Uri. parse ("geo: 100,100"); Intent intent = new Intent (Intent. ACTION_VIEW, mapUri); // play mp3 Uri playUri = Uri. parse ("file: // sdcard/test.pdf"); Intent intent = new Intent (Intent. ACTION_VIEW, playUri); intent. setDataAndType (playUri, "audio/mp3 ");/ /Call the call Uri dialUri = Uri. parse ("tel: 10086"); Intent intent = new Intent (Intent. ACTION_DIAL, dialUri); // call the phone directly. You must add the permission <uses-permission id = "android. permission. CALL_PHONE "/> Uri callUri = Uri. parse ("tel: 10086"); Intent intent = new Intent (Intent. ACTION_CALL, callUri); // call the mail (the system Email must be configured in advance, otherwise the mail interface cannot be called) Uri emailUri = Uri. parse ("mailto: zuolongsnail@163.com"); Intent intent = new Intent (Intent. ACTION_SENDTO, emailUri); // send Intent intent = new Intent (Intent. ACTION_SEND); String [] tos = {"zuolongsnail@gmail.com"}; String [] ccs = {"zuolongsnail@163.com"}; intent. putExtra (Intent. EXTRA_EMAIL, tos); intent. putExtra (Intent. EXTRA_CC, ccs); intent. putExtra (Intent. EXTRA_TEXT, "the email text"); intent. putExtra (Intent. EXTRA_SUBJECT, "subject"); intent. setType ("text/plain"); Intent. create Chooser (intent, "Choose Email Client"); // send a text message Intent intent = new Intent (Intent. ACTION_VIEW); intent. putExtra ("sms_body", "the sms text"); intent. setType ("vnd. android-dir/mms-sms "); // send a text message Uri smsToUri = Uri. parse ("Maid: 10086"); Intent intent = new Intent (Intent. ACTION_SENDTO, smsToUri); intent. putExtra ("sms_body", "the sms text"); // send a MMS Uri mmsUri = Uri. parse ("content: // media/external/images /Media/23 "); Intent intent = new Intent (Intent. ACTION_SEND); intent. putExtra ("sms_body", "the sms text"); intent. putExtra (Intent. EXTRA_STREAM, mmsUri); intent. setType ("image/png"); // uninstall the application Uri uninstallUri = Uri. fromParts ("package", "com. app. test ", null); Intent intent = new Intent (Intent. ACTION_DELETE, uninstallUri); // install the application Intent intent = new Intent (Intent. ACTION_VIEW); intent. setDataAndType (Ur I. fromFile (new File ("/sdcard/test.apk"), "application/vnd. android. package-archive "); // search for the application Uri = uri in the Android Market. parse ("market: // search? Q = Angry Birds "); Intent intent = new Intent (Intent. ACTION_VIEW, uri );
Demo source code
Package mm.shandong.com. testactioncate; import android. content. intent; import android. support. v7.app. appCompatActivity; import android. OS. bundle; import android. view. menu; import android. view. view; public class TestActionCateActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_test_action_cate);} // start activityTestComponentOtherActivity and set intent action to // TestComponentOtherActivity1 public void startActivityToAction1 (View view View) {Intent intent = new Intent (); intent. setAction ("TestComponentOtherActivity1"); startActivity (intent);} // start activityTestComponentOtherActivity and set intent action to // TestComponentOtherActivity2 public void startActivityToAction2 (View view) {Intent intent = new Intent (); intent. setAction ("TestComponentOtherActivity2"); startActivity (intent);} // start activityTestComponentOtherActivity and set intent action to // TestComponentOtherActivity3 public void startActivityToAction3 (View view) {Intent intent = new Intent (); intent. setAction ("TestComponentOtherActivity3"); startActivity (intent);} // start the activity whose action is sameAction. Two of them have the same action public void startActivitySameAction1 (View view) {Intent intent = new Intent (); intent. setAction ("sameAction"); startActivity (intent);} // The start action is Intent. ACTION_VIEW activity, // This action public void startActivitySameAction2 (View view) {Intent intent = new Intent (); intent. setAction (Intent. ACTION_VIEW); startActivity (intent);} // start an activity with three category settings. All category settings must be set. // public void startActivityCategory (View view) can be started) {Intent intent = new Intent (); intent. setAction ("TestActionCate3Activity"); intent. addCategory ("category1"); intent. addCategory ("category2"); intent. addCategory ("category3"); startActivity (intent );}}

 

My microblog: honey_11

Download Demo
Finally, the above examples all come from Android. Please download the sample source code from app Bao or pods: the source code is exhausted by the source code.

Related Article

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.