Introduction to Android URIs

Source: Internet
Author: User
<span id="Label3"></p><p>For android, The URI is divided into three parts: scheme, authority and Path. Among them, authority is divided into host and port. The format is as Follows:<br>Scheme://host:port/path<br>To give a practical example:<br>Content://com.example.project:200/folder/subfolder/etc<br>\---------/  \---------------------------/ \---/ \--------------------------/<br>Scheme Host Port Path<br>\--------------------------------/<br>Authority<br><br>Now you should know what those attributes in Data flag mean, look at the data flag.<br><data android:host= "string"<br>Android:mimetype= "string"<br>Android:path= "string"<br>android:pathpattern= "string"<br>android:pathprefix= "string"<br>Android:port= "string"<br>Android:scheme= "string"/><br>But we generally do not use URIs to identify the CP directly in the program, yes, as we usually see with defined constants to Identify. For example, contacts in the standard cp, we use Contacts.People.CONTENT_URI to identify the people table in the contacts cp. So what do you do to identify a specific person? This uses Contenturis.withappendedid () and Uri.withappendedpath (). For example, if we want to represent content://contacts/people/20, then we can use the following statement:<br>Uri uri = Contenturis.withappendedid (people.content_uri, 20); Or<br>Uri uri = Uri.withappendedpath (people.content_uri, "20");</p><p><p></p></p><p><p>For example, such as:</p></p><p><p>Uri:content://contacts/people of all contact persons</p></p><p><p>The URI:CONTENT://CONTACTS/PEOPLE/5 of a contact.</p></p><p><p>All pictures uri:content://media/external</p></p><p><p>The URI:CONTENT://MEDIA/EXTERNAL/IMAGES/MEDIA/4 of a picture</p></p><p><p>Here are some of the commonly used URIs</p></p><p><p></p></p><p>Show Web Page:<br>1. URI uri = Uri.parse ("http://www.google.com");<br>2. Intent it = new Intent (intent.action_view,uri);<br>3. StartActivity (it);<br><br>Show Map:<br>1. URI uri = Uri.parse ("geo:38.899533,-77.036476");<br>2. Intent it = new Intent (intent.action_view,uri);<br>3. StartActivity (it);<br><br>Path planning:<br>1. URI uri = Uri.parse ("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng &hl=en ");<br>2. Intent it = new Intent (intent.action_view,uri);<br>3. StartActivity (it);<br><br>Dial number:<br>Calling a dial-up program<br>1. URI uri = Uri.parse ("tel:xxxxxx");<br>2. Intent it = new Intent (intent.action_dial, uri);<br>3. StartActivity (it);<br>1. URI uri = Uri.parse ("tel.xxxxxx");<br>2. Intent it =new Intent (intent.action_call,uri);<br>3. To use this, the <uses-permission id= "Android.permission.CALL_PHONE" must be added to the configuration file/><br><br>Send Sms/mms<br>Call the program that sent the SMS<br>1. Intent it = new Intent (intent.action_view);<br>2. It.putextra ("sms_body", "the SMS text");<br>3. It.settype ("vnd.android-dir/mms-sms");<br>4. StartActivity (it);<br>Send SMS<br>1. URI uri = Uri.parse ("smsto:0800000123");<br>2. Intent it = new Intent (intent.action_sendto, uri);<br>3. It.putextra ("sms_body", "the SMS text");<br>4. StartActivity (it);<br>Send MMS<br>1. URI uri = Uri.parse ("content://media/external/images/media/23");<br>2. Intent it = new Intent (intent.action_send);<br>3. It.putextra ("sms_body", "some text");<br>4. It.putextra (intent.extra_stream, uri);<br>5. It.settype ("image/png");<br>6. StartActivity (it);<br><br>Send email<br>1.<br>2. URI uri = uri.parse ("mailto:[email protected]");<br>3. Intent it = new Intent (intent.action_sendto, uri);<br>4. StartActivity (it);<br>1. Intent it = new Intent (intent.action_send);<br>2. It.putextra (intent.extra_email, "[EMAIL protected]");<br>3. It.putextra (intent.extra_text, "the Email Body TEXT");<br>4. It.settype ("text/plain");<br>5. startactivity (intent.createchooser (it, "Choose Email Client"));<br>1. Intent it=new Intent (intent.action_send);<br>2. string[] tos={"[email protected]"};<br>3. string[] Ccs={"[email protected]"};<br>4. It.putextra (intent.extra_email, tos);<br>5. It.putextra (intent.extra_cc, ccs);<br>6. It.putextra (intent.extra_text, "the Email Body TEXT");<br>7. It.putextra (intent.extra_subject, "the Email SUBJECT text");<br>8. It.settype ("message/rfc822");<br>9. startactivity (intent.createchooser (it, "Choose Email Client"));<br><br>Add an attachment<br>1. Intent it = new Intent (intent.action_send);<br>2. It.putextra (intent.extra_subject, "the Email SUBJECT text");<br>3. It.putextra (intent.extra_stream, "[url=]file:///sdcard/mysong.mp3[/url]");<br>4. Sendintent.settype ("audio/mp3");<br>5. startactivity (intent.createchooser (it, "Choose Email Client"));<br><br>Play Multimedia<br>1.<br>2. Intent it = new Intent (intent.action_view);<br>3. URI uri = Uri.parse ("[url=]file:///sdcard/song.mp3[/url]");<br>4. It.setdataandtype (uri, "audio/mp3");<br>5. StartActivity (it);<br>1. URI uri = Uri.withappendedpath (MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");<br>2. Intent it = new Intent (intent.action_view, uri);<br>3. StartActivity (it);<br><br>Uninstall Program<br>1. URI uri = uri.fromparts ("package", strpackagename, null);<br>2. Intent it = new Intent (intent.action_delete, uri);<br>3. StartActivity (it);<br><br>Call album<br>public static final String mime_type_image_jpeg = "image/*";<br>public static final int activity_get_image = 0;<br>Intent getImage = new Intent (intent.action_get_content);<br>Getimage.addcategory (intent.category_openable);<br>Getimage.settype (mime_type_image_jpeg);<br>Startactivityforresult (getImage, activity_get_image);<br><br>Call the System camera application and store the captured photos<br>Intent Intent = new Intent (mediastore.action_image_capture);<br>Time = calendar.getinstance (). gettimeinmillis ();<br>Intent.putextra (mediastore.extra_output, uri.fromfile (new File (environment<br>. getexternalstoragedirectory (). GetAbsolutePath () + "/tucue", time + ". jpg"));<br>Startactivityforresult (intent, activity_get_camera_image);<br><br>Uninstall APK<br>/** not tested<br>Uri Uninstalluri = uri.fromparts ("package", "xxx", null);<br>Returnit = new Intent (intent.action_delete, uninstalluri);<br>*/<br>Uri Packageuri = Uri.parse ("package:" +wistatmap);<br>Intent uninstallintent = new Intent (intent.action_delete, packageuri);<br>StartActivity (uninstallintent);<br><br>Install APK<br>Uri Installuri = uri.fromparts ("package", "xxx", null);<br>Returnit = new Intent (intent.action_package_added, installuri);<br>Play Audio<br>Uri Playuri = Uri.parse ("[url=]file:///sdcard/download/everything.mp3[/url]");<br>Returnit = new Intent (intent.action_view, playuri);<br><br>Send Attachments<br>Intent it = new Intent (intent.action_send);<br>It.putextra (intent.extra_subject, "the Email SUBJECT text");<br>It.putextra (intent.extra_stream, "[url=]file:///sdcard/eoe.mp3[/url]");<br>Sendintent.settype ("audio/mp3");<br>StartActivity (intent.createchooser (it, "Choose Email Client"));<br><br>Search for Apps<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>Go to contact page<br>Intent Intent = new Intent ();<br>Intent.setaction (intent.action_view);<br>Intent.setdata (people.content_uri);<br>StartActivity (intent);<br><br>View specified contacts<br>Uri Personuri = Contenturis.withappendedid (people.content_uri, info.id);//info.id Contact ID<br>Intent Intent = new Intent ();<br>Intent.setaction (intent.action_view);<br>Intent.setdata (personuri);<br>StartActivity (intent);</p><p><p>Introduction to Android URIs</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.