Go: Intent Introduction

Source: Internet
Author: User

Turn from: here

An Android system for activity standard Intent 1 display contact information based on contact ID [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (Intent.action_view); //Show contact information
    3. Intent.setdata (Uri.parse ("content://contacts/people/492"));
    4. StartActivity (Intent);

2 Display dial-up panel based on contact ID [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (intent.action_dial); //Display dial-up panel
    3. Intent.setdata (Uri.parse ("content://contacts/people/492"));
    4. StartActivity (Intent);

3 Display the dialer panel and display the number on the Dial panel [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (Intent.action_view);
    3. Intent.setdata (Uri.parse ("tel://15216448315"));
    4. StartActivity (Intent);

4 Display the dialer panel and display the number on the Dial panel [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (intent.action_dial); //Display the dialer panel and display the number on the Dial panel
    3. Intent.setdata (Uri.parse ("tel://15216448315"));
    4. StartActivity (Intent);

5 Edit contacts based on the ID of the contact person [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (Intent.action_edit); //Edit Contacts
    3. Intent.setdata (Uri.parse ("content://contacts/people/492"));
    4. StartActivity (Intent);

6 displays a list of contacts and other account contacts for the contact person [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (Intent.action_view);
    3. Intent.setdata (Uri.parse ("content://contacts/people/"));
    4. StartActivity (Intent);

7 Start homescreen [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (Intent.action_main); //Start homescreen
    3. Intent.addcategory (Intent.category_home);
    4. StartActivity (Intent);

8 Select a contact's number and return a URI that represents this number, such as: content://contacts/phones/982 [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (intent.action_get_content);
    3. Intent.settype ("Vnd.android.cursor.item/phone");
    4. Startactivityforresult (Intent, 1);

9 Open multiple Apps Select various types of data to return as URIs. The returned URI can be opened using Contentresolver.openinputstream (URI)
This feature can be used to select attachments in a message
Examples are as follows:
Select a picture and return the URI as CONTENT://MEDIA/EXTERNAL/IMAGES/MEDIA/47
Choose a song that returns a URI of CONTENT://MEDIA/EXTERNAL/AUDIO/MEDIA/51 [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (intent.action_get_content);
    3. Intent.settype ("*/*");
    4. Intent.addcategory (intent.category_openable);
    5. Startactivityforresult (Intent, 2);

10 Customizing a Chooser, not using the system's Chooser
The chooser can have its own caption (title)
And you don't have to specify preferences [Java]View Plaincopy
    1. intent intent = new  Intent ();   
    2. intent.setaction (intent.action_chooser);    
    3. intent.putextra (Intent.extra_title,  "My chooser");  
    4. Intent.putextra (intent.extra_intent,   
    5.          new intent (intent.action_get_content)   
    6.         .settype ( "*/*")    
    7.         .addcategory (Intent.CATEGORY _openable)   
    8.         );   
    9.   
    10. Startactivityforresult (Intent, 2);   

11 Select activity, the returned activity can be obtained in the Returned Intent.getcomponent () [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (intent.action_pick_activity);
    3. Intent.putextra (Intent.extra_intent,
    4. new Intent (intent.action_get_content)
    5. . SetType ("*/*")
    6. . Addcategory (Intent.category_openable)
    7. );
    8. Startactivityforresult (Intent, 3);

12 Start the search, in the following sample code, "ANDROID" is the string to search for
When this code is executed, a list of programs that can be used for searching is displayed in the system's Chooser [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (Intent.action_search); //Start Search
    3. Intent.putextra (Searchmanager.query, "ANDROID");
    4. StartActivity (Intent);

13 Start web Search, in the following sample code, "ANDROID" is the string to search for
When this code is executed, a list of programs that can be used for searching is displayed in the system's chooser, and in general the browsers installed in the system will be displayed [Java]View Plaincopy
    1. Intent Intent = new Intent ();
    2. Intent.setaction (Intent.action_web_search); //Start Search
    3. Intent.putextra (Searchmanager.query, "ANDROID");
    4. StartActivity (Intent);
Two Android system for Broadcastreceiver standard Intent 1 Action_time_tick, System clock broadcast, the system sends one such broadcast every minute, if in the application development, some logic relies on the system clock, Can register a broadcast receiver this is a protected action and only the system can send this broadcast and the broadcast recipient registered in the manifest file cannot receive the broadcast, and the broadcast recipient must be registered in the code to receive the broadcast [Java]View Plaincopy
    1. Registerreceiver (new Broadcastreceiver () {
    2. @Override
    3. public void OnReceive (context context, Intent Intent) {
    4. LOG.I ("xxxx", "Time_tick");
    5. }
    6. },
    7. New Intentfilter (Intent.action_time_tick));

2 in the official documentation, the following standard broadcast action is listed
  • ACTION_TIME_TICK               系统时钟广播
  • ACTION_TIME_CHANGED            时间被重新设置
  • ACTION_TIMEZONE_CHANGED        时区改变
  • ACTION_BOOT_COMPLETED          系统启动完成
  • ACTION_PACKAGE_ADDED           系统中安装了新的应用
  • ACTION_PACKAGE_CHANGED         系统中已存在的app包被更改
  • ACTION_PACKAGE_REMOVED         系统中已存在的app被移除
  • ACTION_PACKAGE_RESTARTED       用户重启了一个app,这个app的所有进程被杀死
  • ACTION_PACKAGE_DATA_CLEARED    用户清除了一个app的数据
  • ACTION_UID_REMOVED             系统中的一个user ID被移除
  • ACTION_BATTERY_CHANGED         电池状态改变,这是一个sticky广播
  • ACTION_POWER_CONNECTED         设备连接了外部电源
  • ACTION_POWER_DISCONNECTED      外部电源被移除
  • ACTION_SHUTDOWN                设备正在关机
The three standard category categories (category) in Android generally work with action, and the following are the standard categories in the system, which can only be studied in detail when used, due to excessive quantities
    • CATEGORY_DEFAULT
    • CATEGORY_BROWSABLE
    • CATEGORY_TAB
    • CATEGORY_ALTERNATIVE
    • CATEGORY_SELECTED_ALTERNATIVE
    • CATEGORY_LAUNCHER
    • CATEGORY_INFO
    • CATEGORY_HOME
    • CATEGORY_PREFERENCE
    • CATEGORY_TEST
    • CATEGORY_CAR_DOCK
    • CATEGORY_DESK_DOCK
    • CATEGORY_LE_DESK_DOCK
    • CATEGORY_HE_DESK_DOCK
    • CATEGORY_CAR_MODE
    • CATEGORY_APP_MARKET
Standard extra key values in quad Android These constants are used to pass data as key values when calling Intent.putextra (String, Bundle), and also because of the large number of indexes listed here
  • EXTRA_ALARM_COUNT
  • EXTRA_BCC
  • EXTRA_CC
  • EXTRA_CHANGED_COMPONENT_NAME
  • EXTRA_DATA_REMOVED
  • EXTRA_DOCK_STATE
  • EXTRA_DOCK_STATE_HE_DESK
  • EXTRA_DOCK_STATE_LE_DESK
  • EXTRA_DOCK_STATE_CAR
  • EXTRA_DOCK_STATE_DESK
  • EXTRA_DOCK_STATE_UNDOCKED
  • EXTRA_DONT_KILL_APP
  • EXTRA_EMAIL
  • EXTRA_INITIAL_INTENTS
  • EXTRA_INTENT
  • EXTRA_KEY_EVENT
  • EXTRA_ORIGINATING_URI
  • EXTRA_PHONE_NUMBER
  • EXTRA_REFERRER
  • EXTRA_REMOTE_INTENT_TOKEN
  • EXTRA_REPLACING
  • EXTRA_SHORTCUT_ICON
  • EXTRA_SHORTCUT_ICON_RESOURCE
  • EXTRA_SHORTCUT_INTENT
  • EXTRA_STREAM
  • EXTRA_SHORTCUT_NAME
  • EXTRA_SUBJECT
  • EXTRA_TEMPLATE
  • EXTRA_TEXT
  • EXTRA_TITLE
  • EXTRA_UID
The flag in the intent (flag) Intent class defines some of the flags that begin with flag_, some of which are important and affect the behavior of activity and Broadcastreceiver in the app. The following is an index of these flags, from the official documentation. This will be followed by a detailed analysis of the important signs.

Go: Intent Introduction

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.