Standard intent for activity in Android systems

Source: Internet
Author: User

1 displaying 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);

Standard intent for activity 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.