Android Intent and intent action Daquan

Source: Internet
Author: User
<span id="Label3"></p>Android Intent and intent action Daquan<span style="font-size: 14pt;"><span style="font-size: 14pt;"><strong>usage of 1.Intent:</strong></span></span><strong><strong><span style="font-size: 16px;">(1) jump with action</span></strong></strong>1, Use the action jump, if there is a program in the androidmanifest.xml of an activity<strong>the <strong>intentfilter section defines the same action that is included in</strong> the</strong>Then this intent is matched to this target Action. If type,category is not defined in this intentfilter segment, then the activity is Matched.<strong><strong>But if you have more than two programs in your phone, a dialog box will pop up to show you the Message. </strong></strong>The value of Action has a lot of pre-defined in android,<strong><strong>If you want to go directly to your own defined intent receiver, you can add a custom action value to the Recipient's intentfilter</strong></strong>(also set the category value to "android.intent.category.DEFAULT"), in your intent set the value as intent Action, you can jump directly to your own intent Receiver. Because this action is unique in the System. 2,data/type, you can use URIs as data, such as URI uri = Uri.parse (http://www.google.com);<br>Intent i = new Intent (intent.action_view,uri); during the Intent distribution of the cell phone, the type of data is judged according to the http://www.google.com Scheme. Mobile phone brower can match it, in Brower Manifest.xml Intenfilter in the first there is Action_view Action, also can handle http: type,3, as for classification category, Generally do not go to set it in intent, if you write intent receiver, in manifest.xml activity Intentfilter contains android.category.DEFAULT, so that all do not set The Intent of category (intent.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 your component, such as, if you want to perform the "send e-mail" action, you can save the e-mail message's title, body, and so on in extras, to the e-mail sending Component.<strong><strong>(2) jump with class name</strong></strong>Intent is responsible for the action of an operation in the application, the action involves data, the additional data is described, Android according to this intent description, is responsible to find the corresponding component, the intent passed to the calling component, and complete the call of the Component. Intent is where the decoupling between the caller and the callee is Implemented. In the intent delivery process, the target consumer (another activity,intentreceiver or Service) is found, that is, the responder of Intent. Intent Intent = new Intent ();<br>Intent.setclass (context, targetactivy.class);<br>or directly with Intent Intent = new Intent (context, targetactivity.class); StartActivity (intent);<span><span>but note that using the class name to jump, you need to declare activity in Androidmanifest.xml</span></span><activity android:name= "targetactivity" ></activity><span style="font-size: 14pt;"><span style="font-size: 14pt;"><strong>2. Usage of several intent</strong></span></span>Intent is often used in android. Whether it is the page pull, or pass data, or call external programs, the system functions are used to Intent. After doing some examples of intent, finishing a bit of intent, hope to be useful to EVERYONE. Because intent content too much, can not really write full, inevitably will have left behind, I will be updated at any Time. If you have questions or new intent content, want to Communicate.<br>★intent daquan:<br><span style="font-family: verdana, sans-serif;">1. Search content from Google<br>Intent Intent = new Intent ();<br>Intent.setaction (intent.action_web_search);<br>Intent.putextra (searchmanager.query, "searchstring")<br>StartActivity (intent);<br><br>2. Browse the Web<br>Uri uri = Uri.parse ("http://www.google.com");<br>Intent it = new Intent (intent.action_view,uri);<br>StartActivity (it);<br><br>3. Show Map<br>Uri uri = Uri.parse ("geo:38.899533,-77.036476");<br>Intent it = new Intent (intent.action_view,uri);<br>StartActivity (it);<br><br>4. Path Planning<br>Uri uri = Uri.parse ("http://maps.google.com/maps?f=dsaddr=startLat%20startLng&daddr=endLat%20endLng&hl=en ");<br>Intent it = new Intent (intent.action_view,uri);<br>StartActivity (it);<br><br>5. Make a phone call<br>Uri uri = Uri.parse ("tel:xxxxxx");<br>Intent it = new Intent (intent.action_dial, uri);<br>StartActivity (it);<br><br>6. Call the program to send SMS<br>Intent it = new Intent (intent.action_view);<br>It.putextra ("sms_body", "the SMS text");<br>It.settype ("vnd.android-dir/mms-sms");<br>StartActivity (it);<br><br>7. Send SMS<br>Uri uri = Uri.parse ("smsto:0800000123");<br>Intent it = new Intent (intent.action_sendto, uri);<br>It.putextra ("sms_body", "the SMS text");<br>StartActivity (it);<br>String body= "this is SMS demo";<br>Intent mmsintent = new Intent (intent.action_sendto, uri.fromparts ("smsto", number, null));<br>Mmsintent.putextra (messaging.key_action_sendto_message_body, BODY);<br>Mmsintent.putextra (messaging.key_action_sendto_compose_mode, true);<br>Mmsintent.putextra (messaging.key_action_sendto_exit_on_sent, true);<br>StartActivity (mmsintent);<br><br>8. Send MMS<br>Uri uri = Uri.parse ("content://media/external/images/media/23");<br>Intent it = new Intent (intent.action_send);<br>It.putextra ("sms_body", "some text");<br>It.putextra (intent.extra_stream, uri);<br>It.settype ("image/png");<br>StartActivity (it);<br>StringBuilder sb = new StringBuilder ();<br>Sb.append ("file://");<br>Sb.append (fd.getabsolutefile ());<br>Intent Intent = new Intent (intent.action_sendto, uri.fromparts ("mmsto", number, null));<br>Below extra datas is all optional.<br>Intent.putextra (messaging.key_action_sendto_message_subject, SUBJECT);<br>Intent.putextra (messaging.key_action_sendto_message_body, BODY);<br>Intent.putextra (messaging.key_action_sendto_content_uri, sb.tostring ());<br>Intent.putextra (messaging.key_action_sendto_compose_mode, composemode);<br>Intent.putextra (messaging.key_action_sendto_exit_on_sent, exitonsent);<br>StartActivity (intent);<br><br>9. Send Email<br>Uri uri = uri.parse ("mailto:[email protected]");<br>Intent it = new Intent (intent.action_sendto, uri);<br>StartActivity (it);<br>Intent it = new Intent (intent.action_send);<br>It.putextra (intent.extra_email, "[EMAIL protected]");<br>It.putextra (intent.extra_text, "the Email Body TEXT");<br>It.settype ("text/plain");<br>StartActivity (intent.createchooser (it, "Choose Email Client"));<br>Intent it=new Intent (intent.action_send);<br>string[] Tos={"[email protected]"};<br>string[] Ccs={"[email protected]"};<br>It.putextra (intent.extra_email, tos);<br>It.putextra (intent.extra_cc, ccs);<br>It.putextra (intent.extra_text, "the Email Body TEXT");<br>It.putextra (intent.extra_subject, "the Email SUBJECT text");<br>It.settype ("message/rfc822");<br>StartActivity (intent.createchooser (it, "Choose Email Client"));<br><br>Intent it = new Intent (intent.action_send);<br>It.putextra (intent.extra_subject, "the Email SUBJECT text");<br>It.putextra (intent.extra_stream, "file:///sdcard/mysong.mp3");<br>Sendintent.settype ("audio/mp3");<br>StartActivity (intent.createchooser (it, "Choose Email Client"));<br><br>10. Play Multimedia<br>Intent it = new Intent (intent.action_view);<br>Uri uri = Uri.parse ("file:///sdcard/song.mp3");<br>It.setdataandtype (uri, "audio/mp3");<br>StartActivity (it);<br>Uri uri = Uri.withappendedpath (MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");<br>Intent it = new Intent (intent.action_view, uri);<br>StartActivity (it);<br><br>11.uninstall apk<br>Uri uri = uri.fromparts ("package", strpackagename, null);<br>Intent it = new Intent (intent.action_delete, uri);<br>StartActivity (it);<br><br>12.install apk<br>Uri Installuri = uri.fromparts ("package", "xxx", null);<br>Returnit = new Intent (intent.action_package_added, installuri);<br><span style="font-family: verdana, sans-serif;"><br>13. Turn on the camera<br><span style="font-family: verdana, sans-serif;"><1>intent i = new Intent (intent.action_camera_button, null);<br>This.sendbroadcast (i);<br><2>long Datetaken = System.currenttimemillis ();<br>String name = Createname (datetaken) + ". jpg";<br>FileName = folder + name;<br>Contentvalues values = new Contentvalues ();<br>Values.put (Images.Media.TITLE, fileName);<br>Values.put ("_data", fileName);<br>Values.put (Images.Media.PICASA_ID, fileName);<br>Values.put (Images.Media.DISPLAY_NAME, fileName);<br>Values.put (Images.Media.DESCRIPTION, fileName);<br>Values.put (Images.ImageColumns.BUCKET_DISPLAY_NAME, fileName);<br>Uri Photouri = getcontentresolver (). Insert (<br>MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);<br><br>Intent Inttphoto = new Intent (mediastore.action_image_capture);<br>Inttphoto.putextra (mediastore.extra_output, photouri);<br>Startactivityforresult (inttphoto, 10);<br><br>14. Select a picture from gallery<br>Intent i = new Intent ();<br>I.settype ("image/*");<br>I.setaction (intent.action_get_content);<br>Startactivityforresult (i, 11);<br><br>15. Turn on the recorder<br>Intent mi = new Intent (media.record_sound_action);<br>StartActivity (mi);<br><br>16. Show App Detail list<br>Uri uri = Uri.parse ("market://details?id=app_id");<br>Intent it = new Intent (intent.action_view, uri);<br>StartActivity (it);<br>Where app_id is the application id, find the ID<br>By clicking on your application in market home<br>page, and notice the ID from the address bar<br><br>Just looking for the app ID has not been found, The result finds the package name can also<br>Uri uri = Uri.parse ("market://details?id=<packagename>");<br>That's a lot Easier.<br><br>17 Finding applications<br>Uri uri = Uri.parse ("market://search?q=pname:pkg_name");<br>Intent it = new Intent (intent.action_view, uri);<br>StartActivity (it);<br>Where Pkg_name is the full package path for an application<br><br>18 Open a contact list<br><1><br>Intent i = new Intent ();<br>I.setaction (intent.action_get_content);<br>I.settype ("vnd.android.cursor.item/phone");<br>Startactivityforresult (i, request_text);<br><br><2><br>Uri uri = Uri.parse ("content://contacts/people");<br>Intent it = new Intent (intent.action_pick, uri);<br>Startactivityforresult (it, request_text);<br><br>19 Open Another program<br>Intent i = new Intent ();<br>ComponentName cn = New ComponentName ("com.yellowbook.android2",<br>"com.yellowbook.android2.AndroidSearch");<br>I.setcomponent (cn);<br>I.setaction ("android.intent.action.MAIN");<br>Startactivityforresult (i, result_ok);</span></span></span><span style="font-family: verdana, sans-serif;"><span style="font-family: verdana, sans-serif;"> </span></span><span style="font-family: verdana, sans-serif;">20. Call System Editor to add a contact (the High version SDK is valid):<br style="line-height: normal;">Intent it = newintent (intent.action_insert_or_edit);<br style="line-height: normal;">It.settype ("vnd.android.cursor.item/contact");<br style="line-height: normal;">It.settype (contacts.content_item_type);<br style="line-height: normal;">It.putextra ("name", "myName");<br style="line-height: normal;">It.putextra (android.provider.Contacts.Intents.Insert.COMPANY, "organization");<br style="line-height: normal;">It.putextra (android.provider.Contacts.Intents.Insert.EMAIL, "EMAIL");<br style="line-height: normal;">It.putextra (android.provider.Contacts.Intents.Insert.PHONE, "homephone");<br style="line-height: normal;">It.putextra (android.provider.Contacts.Intents.Insert.SECONDARY_PHONE,<br style="line-height: normal;">"mobilephone");<br style="line-height: normal;">It.putextra (android.provider.Contacts.Intents.Insert.TERTIARY_PHONE,<br style="line-height: normal;">"workphone");<br style="line-height: normal;">It.putextra (android.provider.Contacts.Intents.Insert.JOB_TITLE, "TITLE");<br style="line-height: normal;">StartActivity (it);<br style="line-height: normal;"><br style="line-height: normal;">21. Call system Edit Add contact (all valid):<br style="line-height: normal;">Intent Intent = newintent (intent.action_insert_or_edit);<br style="line-height: normal;">Intent.settype (people.content_item_type);<br style="line-height: normal;">Intent.putextra (Contacts.Intents.Insert.NAME, "My NAME");<br style="line-height: normal;">Intent.putextra (Contacts.Intents.Insert.PHONE, "+1234567890");<br style="line-height: normal;">Intent.putextra (contacts.intents.insert.phone_type,contacts.phonescolumns.type_mobile);<br style="line-height: normal;">Intent.putextra (Contacts.Intents.Insert.EMAIL, "[EMAIL protected]");<br style="line-height: normal;">Intent.putextra (Contacts.Intents.Insert.EMAIL_TYPE, Contacts.ContactMethodsColumns.TYPE_WORK);<br style="line-height: normal;">StartActivity (intent);<br><br>★intent Action Daquan:<br></span> <ul type="1"> <li><li>Android.intent.action.ALL_APPS</li></li> <li><li>Android.intent.action.ANSWER</li></li> <li><li>Android.intent.action.ATTACH_DATA</li></li> <li><li>Android.intent.action.BUG_REPORT</li></li> <li><li>Android.intent.action.CALL</li></li> <li><li>Android.intent.action.CALL_BUTTON</li></li> <li><li>Android.intent.action.CHOOSER</li></li> <li><li>Android.intent.action.CREATE_LIVE_FOLDER</li></li> <li><li>Android.intent.action.CREATE_SHORTCUT</li></li> <li><li>Android.intent.action.DELETE</li></li> <li><li>Android.intent.action.DIAL</li></li> <li><li>Android.intent.action.EDIT</li></li> <li><li>Android.intent.action.GET_CONTENT</li></li> <li><li>Android.intent.action.INSERT</li></li> <li><li>Android.intent.action.INSERT_OR_EDIT</li></li> <li><li>Android.intent.action.MAIN</li></li> <li><li>Android.intent.action.MEDIA_SEARCH</li></li> <li><li>Android.intent.action.PICK</li></li> <li><li>Android.intent.action.PICK_ACTIVITY</li></li> <li><li>Android.intent.action.RINGTONE_PICKER</li></li> <li><li>Android.intent.action.RUN</li></li> <li><li>Android.intent.action.SEARCH</li></li> <li><li>Android.intent.action.SEARCH_LONG_PRESS</li></li> <li><li>Android.intent.action.SEND</li></li> <li><li>Android.intent.action.SENDTO</li></li> <li><li>Android.intent.action.SET_WALLPAPER</li></li> <li><li>Android.intent.action.SYNC</li></li> <li><li>Android.intent.action.SYSTEM_TUTORIAL</li></li> <li><li>Android.intent.action.VIEW</li></li> <li><li>Android.intent.action.VOICE_COMMAND</li></li> <li><li>Android.intent.action.WEB_SEARCH</li></li> <li><li>Android.net.wifi.PICK_WIFI_NETWORK</li></li> <li><li>Android.settings.AIRPLANE_MODE_SETTINGS</li></li> <li><li>Android.settings.APN_SETTINGS</li></li> <li><li>Android.settings.APPLICATION_DEVELOPMENT_SETTINGS</li></li> <li><li>Android.settings.APPLICATION_SETTINGS</li></li> <li><li>Android.settings.BLUETOOTH_SETTINGS</li></li> <li><li>Android.settings.DATA_ROAMING_SETTINGS</li></li> <li><li>Android.settings.DATE_SETTINGS</li></li> <li><li>Android.settings.DISPLAY_SETTINGS</li></li> <li><li>Android.settings.INPUT_METHOD_SETTINGS</li></li> <li><li>Android.settings.INTERNAL_STORAGE_SETTINGS</li></li> <li><li>Android.settings.LOCALE_SETTINGS</li></li> <li><li>Android.settings.LOCATION_SOURCE_SETTINGS</li></li> <li><li>Android.settings.MANAGE_APPLICATIONS_SETTINGS</li></li> <li><li>Android.settings.MEMORY_CARD_SETTINGS</li></li> <li><li>Android.settings.NETWORK_OPERATOR_SETTINGS</li></li> <li><li>Android.settings.QUICK_LAUNCH_SETTINGS</li></li> <li><li>Android.settings.SECURITY_SETTINGS</li></li> <li><li>Android.settings.SETTINGS</li></li> <li><li>Android.settings.SOUND_SETTINGS</li></li> <li><li>Android.settings.SYNC_SETTINGS</li></li> <li><li>Android.settings.USER_DICTIONARY_SETTINGS</li></li> <li><li>Android.settings.WIFI_IP_SETTINGS</li></li> <li><li>Android.settings.WIFI_SETTINGS</li></li> <li><li>Android.settings.WIRELESS_SETTINGS</li></li> </ul>Transferred from: http://www.cnblogs.com/playing/archive/2010/09/15/1826918.html<p><p>Android Intent and intent action Daquan</p></p></span>

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.