Android intent and intent action Overview

Source: Internet
Author: User
1. Intent usage: (1) Jump with action1. Use action to jump. If there is an activity in androidmanifest. xml of a program The intentfilter segment defines the same action.The intent matches the target action. If type and category are not defined in the intentfilter segment, the activity matches. However, if there are more than two matching programs on the phone, a dialog box will pop up to indicate the matching.The value of action has many predefined meanings in Android, If you want to directly go to your own intent receiver, you can add a custom action value to the receiver's intentfilter.(Set the category value to "android. intent. category. default "), set this value to the intent action in your intent, you can directly jump to your own intent receiver. This action is unique in the system. 2, data/type, you can use URI as data, such as Uri uri = URI. parse (http://www.google.com );
Intent I = new intent (intent. action_view, Uri); In the intent distribution process of the phone, the data type is determined based on the scheme of the http://www.google.com. The phone's Brower can match it, in the Brower's manifest. the intenfilter in XML contains action_view action, which can also process HTTP: type, 3. As for classification category, do not set it in intent. If you write the intent receiver, in manifest. the intentfilter of XML activity contains android. category. default, so that all category (intent. the intent of addcategory (string C);) will match this category. 4. Extras (additional information) is a collection of all other additional information. You can use extras to provide extended information for components. For example, if you want to perform the "send email" operation, you can save the email title and body in extras, send to the email sending component. (2) jump by Class NameIntent is responsible for describing the actions, actions involving data, and additional data of an application. Android is responsible for finding the corresponding components based on the description of this intent, pass intent to the called component and complete the call of the component. Intent serves as a decoupling between the caller and the called. During intent transmission, you need to find the target consumer (another activity, intentreceiver or service), that is, the listener of intent. Intent intent = new intent ();
Intent. setclass (context, targetactivy. Class );
// Or directly use intent = new intent (context, targetactivity. Class );
Startactivity (intent); however, note that you must declare activity in androidmanifest. xml. <activity Android: Name = "targetactivity"> </activity> 2. Usage of several intent typesIntent is frequently used in Android. Intent is used for system functions, whether it is page redirection, data transmission, or external program calling. After some intent examples, I sorted out the intent and hoped it would be useful to everyone. Because there are too many intent content, it is impossible to write it completely, and it will inevitably be left blank. I will update it at any time in the future. If you have any questions or new intent content, please contact us.
★Intent Daquan:
1. Search for content from Google
Intent intent = new intent ();
Intent. setaction (intent. action_web_search );
Intent. putextra (searchmanager. query, "searchstring ")
Startactivity (intent );

2. Browse the webpage
Uri uri = URI. parse ("http://www.google.com ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );

3. display a map
Uri uri = URI. parse ("Geo: 38.899533,-77.036476 ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );

4. Route Planning
Uri uri = URI. parse ("http://maps.google.com/maps? F = dsaddr = startlat % 20 startlng & daddr = endlat % 20 endlng & HL = EN ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );

5. Call
Uri uri = URI. parse ("Tel: xxxxxx ");
Intent it = new intent (intent. action_dial, Uri );
Startactivity (it );

6. Call the SMS Program
Intent it = new intent (intent. action_view );
It. putextra ("sms_body", "the SMS text ");
It. settype ("Vnd. Android-DIR/MMS-SMS ");
Startactivity (it );

7. send SMS
Uri uri = URI. parse ("smsto: 0800000123 ");
Intent it = new intent (intent. action_sendto, Uri );
It. putextra ("sms_body", "the SMS text ");
Startactivity (it );
String body = "this is SMS Demo ";
Intent mmsintent = new intent (intent. action_sendto, Uri. fromparts ("smsto", number, null ));
Mmsintent. putextra (messaging. key_action_sendto_message_body, body );
Mmsintent. putextra (messaging. key_action_sendto_compose_mode, true );
Mmsintent. putextra (messaging. key_action_sendto_exit_on_sent, true );
Startactivity (mmsintent );

8. Send MMS
Uri uri = URI. parse ("content: // media/external/images/Media/23 ");
Intent it = new intent (intent. action_send );
It. putextra ("sms_body", "some text ");
It. putextra (intent. extra_stream, Uri );
It. settype ("image/PNG ");
Startactivity (it );
Stringbuilder sb = new stringbuilder ();
SB. append ("file ://");
SB. append (FD. getabsolutefile ());
Intent intent = new intent (intent. action_sendto, Uri. fromparts ("mmsto", number, null ));
// Below extra datas are all optional.
Intent. putextra (messaging. key_action_sendto_message_subject, subject );
Intent. putextra (messaging. key_action_sendto_message_body, body );
Intent. putextra (messaging. key_action_sendto_content_uri, SB. tostring ());
Intent. putextra (messaging. key_action_sendto_compose_mode, composemode );
Intent. putextra (messaging. key_action_sendto_exit_on_sent, exitonsent );
Startactivity (intent );

9. Send email
Uri uri = URI. parse ("mailto: xxx@abc.com ");
Intent it = new intent (intent. action_sendto, Uri );
Startactivity (it );
Intent it = new intent (intent. action_send );
It. putextra (intent. extra_email, "me@abc.com ");
It. putextra (intent. extra_text, "the email body text ");
It. settype ("text/plain ");
Startactivity (intent. createchooser (IT, "Choose email client "));
Intent it = new intent (intent. action_send );
String [] TOS = {"me@abc.com "};
String [] CCS = {"you@abc.com "};
It. putextra (intent. extra_email, TOS );
It. putextra (intent. extra_cc, CCS );
It. putextra (intent. extra_text, "the email body text ");
It. putextra (intent. extra_subject, "the email subject text ");
It. settype ("message/rfc822 ");
Startactivity (intent. createchooser (IT, "Choose email client "));

Intent it = new intent (intent. action_send );
It. putextra (intent. extra_subject, "the email subject text ");
It. putextra (intent. extra_stream, "file: // sdcard/mysong.mp3 ");
Sendintent. settype ("audio/MP3 ");
Startactivity (intent. createchooser (IT, "Choose email client "));

10. Play multimedia
Intent it = new intent (intent. action_view );
Uri uri = URI. parse ("file: // sdcard/song.mp3 ");
It. setdataandtype (Uri, "audio/MP3 ");
Startactivity (it );
Uri uri = URI. withappendedpath (mediastore. Audio. Media. internal_content_uri, "1 ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );

11. Uninstall APK
Uri uri = URI. fromparts ("package", strpackagename, null );
Intent it = new intent (intent. action_delete, Uri );
Startactivity (it );

12. Install APK
Uri installuri = URI. fromparts ("package", "XXX", null );
Returnit = new intent (intent. action_package_added, installuri );

13. Open the camera
<1> intent I = new intent (intent. action_camera_button, null );
This. sendbroadcast (I );
<2> long datetaken = system. currenttimemillis ();
String name = createname (datetaken) + ". jpg ";
Filename = folder + name;
Contentvalues values = new contentvalues ();
Values. Put (images. Media. Title, filename );
Values. Put ("_ data", filename );
Values. Put (images. Media. picasa_id, filename );
Values. Put (images. Media. display_name, filename );
Values. Put (images. Media. Description, filename );
Values. Put (images. imagecolumns. bucket_display_name, filename );
Uri photouri = getcontentresolver (). insert (
Mediastore. Images. Media. external_content_uri, values );

Intent inttphoto = new intent (mediastore. action_image_capture );
Inttphoto. putextra (mediastore. extra_output, photouri );
Startactivityforresult (inttphoto, 10 );

14. Select an image from gallery
Intent I = new intent ();
I. settype ("image /*");
I. setaction (intent. action_get_content );
Startactivityforresult (I, 11 );

15. Enable the recorder
Intent MI = new intent (media. record_sound_action );
Startactivity (MI );

16. display the detailed list of applications
Uri uri = URI. parse ("Market: // details? Id = app_id ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );
// Where app_id is the Application ID, find the ID
// By clicking on your application on market Home
// Page, and notice the ID from the address bar

Failed to find the app Id just now. It turns out that the package name can also be used.
Uri uri = URI. parse ("Market: // details? Id = <packagename> ");
This is much simpler.

17. Search for Applications
Uri uri = URI. parse ("Market: // search? Q = pname: pkg_name ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );
// Where pkg_name is the full package path for an application

18 open the contact list
<1>
Intent I = new intent ();
I. setaction (intent. action_get_content );
I. settype ("Vnd. Android. cursor. Item/phone ");
Startactivityforresult (I, request_text );

<2>
Uri uri = URI. parse ("content: // contacts/People ");
Intent it = new intent (intent. action_pick, Uri );
Startactivityforresult (it, request_text );

19 open another program
Intent I = new intent ();
Componentname Cn = new componentname ("com. yellowbook. android2 ",
"Com. yellowbook. android2.androidsearch ");
I. setcomponent (CN );
I. setaction ("android. Intent. Action. Main ");
Startactivityforresult (I, result_ OK );
20. Call the system editor to add a contact (for later SDK versions ):

Intent it = newintent (intent. action_insert_or_edit );

It. settype ("Vnd. Android. cursor. Item/contact ");

// It. settype (contacts. content_item_type );

It. putextra ("name", "myname ");

It. putextra (Android. provider. Contacts. intents. Insert. Company, "Organization ");

It. putextra (Android. provider. Contacts. intents. Insert. email, "email ");

It. putextra (Android. provider. Contacts. intents. Insert. Phone, "homephone ");

It. putextra (Android. provider. Contacts. intents. Insert. secondary_phone,

"Mobilephone ");

It. putextra (Android. provider. Contacts. intents. Insert. tertiary_phone,

"Workphone ");

It. putextra (Android. provider. Contacts. intents. Insert. job_title, "title ");

Startactivity (it );

 

21. Call the system editor to add a contact (all valid ):

Intent intent = newintent (intent. action_insert_or_edit );

Intent. settype (people. content_item_type );

Intent. putextra (contacts. intents. Insert. Name, "my name ");

Intent. putextra (contacts. intents. Insert. Phone, "+ 1234567890 ");

Intent. putextra (contacts. intents. Insert. phone_type, contacts. phonescolumns. type_mobile );

Intent. putextra (contacts. intents. Insert. email, "com@com.com ");

Intent. putextra (contacts. intents. Insert. email_type, contacts. contactmethodscolumns. type_work );

Startactivity (intent );

★Intent action Daquan:

  • Android. Intent. Action. all_apps
  • Android. Intent. Action. Answer
  • Android. Intent. Action. attach_data
  • Android. Intent. Action. bug_report
  • Android. Intent. Action. Call
  • Android. Intent. Action. call_button
  • Android. Intent. Action. chooser
  • Android. Intent. Action. create_live_folder
  • Android. Intent. Action. create_shortcut
  • Android. Intent. Action. Delete
  • Android. Intent. Action. Dial
  • Android. Intent. Action. Edit
  • Android. Intent. Action. get_content
  • Android. Intent. Action. insert
  • Android. Intent. Action. insert_or_edit
  • Android. Intent. Action. Main
  • Android. Intent. Action. media_search
  • Android. Intent. Action. Pick
  • Android. Intent. Action. pick_activity
  • Android. Intent. Action. ringtone_picker
  • Android. Intent. Action. Run
  • Android. Intent. Action. Search
  • Android. Intent. Action. search_long_press
  • Android. Intent. Action. Send
  • Android. Intent. Action. sendto
  • Android. Intent. Action. set_wallpaper
  • Android. Intent. Action. sync
  • Android. Intent. Action. system_tutorial
  • Android. Intent. Action. View
  • Android. Intent. Action. voice_command
  • Android. Intent. Action. web_search
  • Android.net. Wifi. pick_wifi_network
  • Android. settings. airplane_mode_settings
  • Android. settings. apn_settings
  • Android. settings. application_development_settings
  • Android. settings. application_settings
  • Android. settings. effecth_settings
  • Android. settings. data_roaming_settings
  • Android. settings. date_settings
  • Android. settings. display_settings
  • Android. settings. input_method_settings
  • Android. settings. internal_storage_settings
  • Android. settings. locale_settings
  • Android. settings. location_source_settings
  • Android. settings. manage_applications_settings
  • Android. settings. memory_card_settings
  • Android. settings. network_operator_settings
  • Android. settings. quick_launch_settings
  • Android. settings. security_settings
  • Android. settings. Settings
  • Android. settings. sound_settings
  • Android. settings. sync_settings
  • Android. settings. user_dictionary_settings
  • Android. settings. wifi_ip_settings
  • Android. settings. wifi_settings
  • Android. settings. wireless_settings
Reprinted from: http://www.ophonesdn.com/forum/thread-2609-1-1.html

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.