Use of standard intent in Android systems

Source: Internet
Author: User

Standard intent for activity in an Android system
1 displaying contact information based on contact ID
Intent Intent = new Intent (); intent.setaction (Intent.action_view);   Show contact Information Intent.setdata (uri.parse ("content://contacts/people/492")); StartActivity (intent);

2 Display dial-up panel based on contact ID
Intent Intent = new Intent (); intent.setaction (intent.action_dial);  Display Dial panel intent.setdata (uri.parse ("content://contacts/people/492")); StartActivity (intent);

3 Display the dialer panel and display the number on the Dial panel
Intent Intent = new Intent (); intent.setaction (Intent.action_view);   Intent.setdata (Uri.parse ("tel://15216448315")); StartActivity (intent);

4 Display the dialer panel and display the number on the Dial panel
Intent Intent = new Intent (); intent.setaction (intent.action_dial);   Displays the dialer panel and displays the number on the Dial panel intent.setdata (uri.parse ("tel://15216448315")); StartActivity (intent);

5 Edit contacts based on the ID of the contact person
Intent Intent = new Intent (); intent.setaction (intent.action_edit);   Edit Contact Intent.setdata (Uri.parse ("content://contacts/people/492")); StartActivity (intent);

6 displays a list of contacts and other account contacts for the contact person
Intent Intent = new Intent (); intent.setaction (Intent.action_view);   Intent.setdata (Uri.parse ("content://contacts/people/")); StartActivity (intent);

7 Start homescreen
Intent Intent = new Intent (); intent.setaction (intent.action_main);     Start Homescreenintent.addcategory (intent.category_home); startactivity (Intent);

8 Select a contact's number and return a URI that represents this number, such as: content://contacts/phones/982
Intent Intent = new Intent (); intent.setaction (intent.action_get_content);     Intent.settype ("Vnd.android.cursor.item/phone"); 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
Intent Intent = new Intent (); intent.setaction (intent.action_get_content);     Intent.settype ("*/*"); Intent.addcategory (intent.category_openable); 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
Intent Intent = new Intent (); intent.setaction (Intent.action_chooser); Intent.putextra (Intent.extra_title, "My Chooser"); Intent.putextra (Intent.extra_intent, New intent (Intent.action_ get_content). SetType ("*/*"). Addcategory (intent.category_openable)); Startactivityforresult (Intent, 2);

11 Select activity, the returned activity can be obtained in the Returned Intent.getcomponent ()
Intent Intent = new Intent (); intent.setaction (intent.action_pick_activity); Intent.putextra (Intent.extra_intent, New Intent (intent.action_get_content). SetType ("*/*"). Addcategory ( intent.category_openable)); 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
Intent Intent = new Intent (); intent.setaction (intent.action_search);     Launch Search Intent.putextra (searchmanager.query, "ANDROID"); 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
Intent Intent = new Intent (); intent.setaction (intent.action_web_search);     Launch Search Intent.putextra (searchmanager.query, "ANDROID"); StartActivity (intent);


Two Android systems for Broadcastreceiver standard intent
1 Action_time_tick, System clock broadcast, the system will send a broadcast every minute, if in the application development, some logic depends on the system clock, you can register a broadcast receiver This is a protected ACTION, only the system can send this broadcast and, in Mani The broadcast recipient registered in the Fest file cannot receive the broadcast, and the broadcast recipient must be registered in the code to receive the broadcast
Registerreceiver (New Broadcastreceiver () {@Overridepublic void OnReceive (context context, Intent Intent) {log.i ("xxxx" , "Time_tick");}, 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                设备正在关机

Three standard categories (category) in Android
Category is generally used in conjunction with action, the following are the standard categories in the system, due to the number of excessive, can only be used in the detailed study
    • 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

Signs in five intent (flag)
Some of the flags that begin with FLAG_ are defined in the intent class, 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.

Use of standard intent in Android systems

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.