Several uses of the Android intent detailed analysis _android

Source: Internet
Author: User

Intent should be considered something peculiar to Android. You can specify in intent the action to be performed by the program (for example, view,edit,dial), and the data that the program needs to perform to the action. is specified, the Android system automatically looks for the application that best meets your specific requirements and executes the program as soon as the startactivity () is invoked.

The following is a list of the uses of several intent
Display Web pages:

Copy Code code as follows:

Uri uri = uri.parse ("http://www.google.com");
Intent it = new Intent (Intent.action_view,uri);
StartActivity (IT);

Show Map:
Copy Code code as follows:

Uri uri = uri.parse ("geo:38.899533,-77.036476");
Intent it = new Intent (Intent.action_view,uri);
StartActivity (IT);

Path planning:
Copy Code code as follows:

Uri uri = Uri.parse ("http://maps.google.com/maps?f=d&saddr=startlat%20startlng&daddr=endlat%20endlng& Hl=en ");
Intent it = new Intent (Intent.action_view,uri);
StartActivity (IT);

Dial number:
Calling dialing Programs
Copy Code code as follows:

Uri uri = uri.parse ("tel:xxxxxx");
Intent it = new Intent (intent.action_dial, URI);
StartActivity (IT);
Uri uri = uri.parse ("tel.xxxxxx");
Intent it =new Intent (Intent.action_call,uri);

To use this, you must add <uses-permission id= "Android.permission.CALL_PHONE" to the configuration file/>
Send Sms/mms
Call the program that sent the message
Copy Code code as follows:

Intent it = new Intent (Intent.action_view);
It.putextra ("Sms_body", "The SMS Text");
It.settype ("vnd.android-dir/mms-sms");
StartActivity (IT);

Send SMS
Copy Code code as follows:

Uri uri = uri.parse ("smsto:0800000123");
Intent it = new Intent (intent.action_sendto, URI);
It.putextra ("Sms_body", "The SMS Text");
StartActivity (IT);

Send MMS
Copy Code code as follows:

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

Send email
Copy Code code as follows:

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"));

Add attachment
Copy Code code as follows:

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"));

Play Multimedia
Copy Code code as follows:

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

Uninstall Program
Copy Code code as follows:

Uri uri = uri.fromparts ("package", strpackagename, NULL);
Intent it = new Intent (Intent.action_delete, URI);
StartActivity (IT);

Related Article

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.