Android URI Simple Introduction

Source: Internet
Author: User

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:
Scheme://host:port/path
To give a practical example:
Content://com.example.project:200/folder/subfolder/etc
\---------/  \---------------------------/ \---/ \--------------------------/
Scheme Host Port Path
\--------------------------------/
Authority

Now you should know what those attributes in data flag mean, look at the data flag.
<data android:host= "string"
Android:mimetype= "string"
Android:path= "string"
Android:pathpattern= "string"
android:pathprefix= "string"
Android:port= "string"
Android:scheme= "string"/>
However, we usually 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 detailed 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 statements:
Uri uri = Contenturis.withappendedid (People.content_uri, 20); Or
Uri uri = Uri.withappendedpath (People.content_uri, "20");

Give some examples, such as:

Uri:content://contacts/people of all contact persons

The URI:CONTENT://CONTACTS/PEOPLE/5 of a contact.

All pictures uri:content://media/external

The URI:CONTENT://MEDIA/EXTERNAL/IMAGES/MEDIA/4 of a picture

Here are some of the frequently used URIs

Show Web page:
1. Uri uri = uri.parse ("http://www.google.com");
2. Intent it = new Intent (Intent.action_view,uri);
3. StartActivity (it);

Show Map:
1. Uri uri = uri.parse ("geo:38.899533,-77.036476");
2. Intent it = new Intent (Intent.action_view,uri);
3. StartActivity (it);

Path planning:
1. Uri uri = uri.parse ("Http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng &hl=en ");
2. Intent it = new Intent (Intent.action_view,uri);
3. StartActivity (it);

Dial number:
Calling a dial-up program
1. Uri uri = uri.parse ("tel:xxxxxx");
2. Intent it = new Intent (intent.action_dial, URI);
3. StartActivity (it);
1. Uri uri = uri.parse ("tel.xxxxxx");
2. Intent it =new Intent (Intent.action_call,uri);
3. To use this you must add <uses-permission id= "Android.permission.CALL_PHONE" in the configuration file/>

Send Sms/mms
Call the program that sent the SMS
1. Intent it = new Intent (Intent.action_view);
2. It.putextra ("Sms_body", "The SMS Text");
3. It.settype ("vnd.android-dir/mms-sms");
4. StartActivity (it);
Send SMS
1. Uri uri = uri.parse ("smsto:0800000123");
2. Intent it = new Intent (intent.action_sendto, URI);
3. It.putextra ("Sms_body", "The SMS Text");
4. StartActivity (it);
Send MMS
1. Uri uri = uri.parse ("Content://media/external/images/media/23");
2. Intent it = new Intent (intent.action_send);
3. It.putextra ("Sms_body", "some text");
4. It.putextra (Intent.extra_stream, URI);
5. It.settype ("Image/png");
6. StartActivity (it);

Send email
1.
2. Uri uri = uri.parse ("Mailto:[email protected]");
3. Intent it = new Intent (intent.action_sendto, URI);
4. StartActivity (it);
1. Intent it = new Intent (intent.action_send);
2. It.putextra (Intent.extra_email, "[EMAIL protected]");
3. It.putextra (Intent.extra_text, "The email body TEXT");
4. It.settype ("Text/plain");
5. StartActivity (Intent.createchooser (it, "Choose Email Client"));
1. Intent it=new Intent (intent.action_send);
2. string[] tos={"[Email protected]"};
3. string[] ccs={"[Email protected]"};
4. It.putextra (Intent.extra_email, TOS);
5. It.putextra (INTENT.EXTRA_CC, CCS);
6. It.putextra (Intent.extra_text, "The email body TEXT");
7. It.putextra (Intent.extra_subject, "The email SUBJECT text");
8. It.settype ("message/rfc822");
9. StartActivity (Intent.createchooser (it, "Choose Email Client"));

Add to Attachment
1. Intent it = new Intent (intent.action_send);
2. It.putextra (Intent.extra_subject, "The email SUBJECT text");
3. It.putextra (Intent.extra_stream, "[Url=]file:///sdcard/mysong.mp3[/url]");
4. Sendintent.settype ("Audio/mp3");
5. StartActivity (Intent.createchooser (it, "Choose Email Client"));

Play Multimedia
1.
2. Intent it = new Intent (Intent.action_view);
3. Uri uri = Uri.parse ("[Url=]file:///sdcard/song.mp3[/url]");
4. It.setdataandtype (URI, "Audio/mp3");
5. StartActivity (IT);
1. Uri uri = Uri.withappendedpath (MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
2. Intent it = new Intent (Intent.action_view, URI);
3. StartActivity (it);

Uninstall Program
1. Uri uri = uri.fromparts ("package", strpackagename, NULL);
2. Intent it = new Intent (Intent.action_delete, URI);
3. StartActivity (it);

Call a Brochure
public static final String mime_type_image_jpeg = "image/*";
public static final int activity_get_image = 0;
Intent getImage = new Intent (intent.action_get_content);
Getimage.addcategory (intent.category_openable);
Getimage.settype (Mime_type_image_jpeg);
Startactivityforresult (GetImage, activity_get_image);

Call the System camera application and store the captured photos
Intent Intent = new Intent (mediastore.action_image_capture);
Time = Calendar.getinstance (). Gettimeinmillis ();
Intent.putextra (Mediastore.extra_output, Uri.fromfile (new File (Environment
. getExternalStorageDirectory (). GetAbsolutePath () + "/tucue", Time + ". jpg"));
Startactivityforresult (Intent, activity_get_camera_image);

Uninstall APK
/** not tested
Uri Uninstalluri = uri.fromparts ("package", "XXX", null);
Returnit = new Intent (Intent.action_delete, Uninstalluri);
*/
Uri Packageuri = Uri.parse ("package:" +wistatmap);
Intent uninstallintent = new Intent (Intent.action_delete, Packageuri);
StartActivity (uninstallintent);

Install APK
Uri Installuri = uri.fromparts ("package", "XXX", null);
Returnit = new Intent (intent.action_package_added, Installuri);
Play Audio
Uri Playuri = Uri.parse ("[Url=]file:///sdcard/download/everything.mp3[/url]");
Returnit = new Intent (Intent.action_view, Playuri);

Send Attachments
Intent it = new Intent (intent.action_send);
It.putextra (Intent.extra_subject, "The email SUBJECT text");
It.putextra (Intent.extra_stream, "[Url=]file:///sdcard/eoe.mp3[/url]");
Sendintent.settype ("Audio/mp3");
StartActivity (Intent.createchooser (it, "Choose Email Client"));

Search for Apps
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

Go to contact page
Intent Intent = new Intent ();
Intent.setaction (Intent.action_view);
Intent.setdata (People.content_uri);
StartActivity (Intent);

View specified contacts
Uri Personuri = Contenturis.withappendedid (People.content_uri, info.id);//info.id Contact ID
Intent Intent = new Intent ();
Intent.setaction (Intent.action_view);
Intent.setdata (Personuri);
StartActivity (Intent);

Android URI Simple Introduction

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.