Full summary of Android Intent usage

Source: Internet
Author: User

[Code] Call dialer
10086 Call to mobile customer service
Uri uri = uri.parse ("tel:10086");
Intent Intent = new Intent (intent.action_dial, URI);
StartActivity (Intent);


[Code] send SMS or MMS
Send SMS to 10086 with "Hello" content
Uri uri = uri.parse ("smsto:10086");
Intent Intent = new Intent (intent.action_sendto, URI);
Intent.putextra ("Sms_body", "Hello");
StartActivity (Intent);
Send MMS (equivalent to sending SMS with attachments)
Intent Intent = new Intent (intent.action_send);
Intent.putextra ("Sms_body", "Hello");
Uri uri = uri.parse ("Content://media/external/images/media/23");
Intent.putextra (Intent.extra_stream, URI);
Intent.settype ("Image/png");
StartActivity (Intent);


[Code] open Web page via browser
Open Google home page
Uri uri = uri.parse ("http://www.google.com");
Intent Intent = new Intent (Intent.action_view, URI);
StartActivity (Intent);


[Code] Send e-mail
Send email to [email protected]
Uri uri = uri.parse ("Mailto:[email protected]");
Intent Intent = new Intent (intent.action_sendto, URI);
StartActivity (Intent);
Email "Hello" to [email protected]
Intent Intent = new Intent (intent.action_send);
Intent.putextra (Intent.extra_email, "[EMAIL protected]");
Intent.putextra (Intent.extra_subject, "SUBJECT");
Intent.putextra (Intent.extra_text, "Hello");
Intent.settype ("Text/plain");
StartActivity (Intent);
Send e-mails to multiple people
Intent intent=new Intent (intent.action_send);
String[] tos = {"[email protected]", "[Email protected]"}; Recipient
String[] CCS = {"[email protected]", "[Email protected]"}; Cc
String[] BCCs = {"[email protected]", "[Email protected]"}; Secret delivery
Intent.putextra (Intent.extra_email, TOS);
Intent.putextra (INTENT.EXTRA_CC, CCS);
Intent.putextra (INTENT.EXTRA_BCC, BCCs);
Intent.putextra (Intent.extra_subject, "SUBJECT");
Intent.putextra (Intent.extra_text, "Hello");
Intent.settype ("message/rfc822");
StartActivity (Intent);


[Code] show map and path planning
Open Google Maps China Beijing location (latitude 39.9, longitude 116.3)
Uri uri = uri.parse ("geo:39.9,116.3");
Intent Intent = new Intent (Intent.action_view, URI);
StartActivity (Intent);
Path planning: From Somewhere in Beijing (latitude 39.9, longitude 116.3) to a place in Shanghai (latitude 31.2, longitude 121.4)
Uri uri = Uri.parse ("http://maps.google.com/maps?f=d&saddr=39.9 116.3&daddr=31.2 121.4");
Intent Intent = new Intent (Intent.action_view, URI);
StartActivity (Intent);


[Code] Play Multimedia
Intent Intent = new Intent (Intent.action_view);
Uri uri = uri.parse ("File:///sdcard/foo.mp3");
Intent.setdataandtype (URI, "Audio/mp3");
StartActivity (Intent);

Uri uri = Uri.withappendedpath (MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent Intent = new Intent (Intent.action_view, URI);
StartActivity (Intent);


[Code] taking pictures
Open the Camera program
Intent Intent = new Intent (mediastore.action_image_capture);
Startactivityforresult (Intent, 0);
Remove Photo data
Bundle extras = Intent.getextras ();
Bitmap Bitmap = (Bitmap) extras.get ("Data");


[Code] Get and cut a picture
Get and cut a picture
Intent Intent = new Intent (intent.action_get_content);
Intent.settype ("image/*");
Intent.putextra ("Crop", "true"); Open cut
Intent.putextra ("Aspectx", 1); The width-to-height ratio of the cut is 1:2
Intent.putextra ("Aspecty", 2);
Intent.putextra ("Outputx", 20); Save picture width and height
Intent.putextra ("Outputy", 40);
Intent.putextra ("Output", Uri.fromfile (New File ("/mnt/sdcard/temp")); Save path
Intent.putextra ("OutputFormat", "JPEG");//return format
Startactivityforresult (Intent, 0);
Cut a specific picture
Intent Intent = new Intent ("Com.android.camera.action.CROP");
Intent.setclassname ("Com.android.camera", "com.android.camera.CropImage");
Intent.setdata (Uri.fromfile ("New File") ("/mnt/sdcard/temp"));
Intent.putextra ("Outputx", 1); The width-to-height ratio of the cut is 1:2
Intent.putextra ("Outputy", 2);
Intent.putextra ("Aspectx", 20); Save picture width and height
Intent.putextra ("Aspecty", 40);
Intent.putextra ("scale", true);
Intent.putextra ("Nofacedetection", true);
Intent.putextra ("Output", Uri.parse ("file:///mnt/sdcard/temp"));
Startactivityforresult (Intent, 0);


[Code] Open Google Market
Open Google market and go directly to the details page of the program
Uri uri = uri.parse ("market://details?id=" + "Com.demo.app");
Intent Intent = new Intent (Intent.action_view, URI);
StartActivity (Intent);


[Code] install and uninstall programs
Uri uri = uri.fromparts ("package", "Com.demo.app", null);
Intent Intent = new Intent (Intent.action_delete, URI);
StartActivity (Intent);


[Code] into the Setup interface

Access to the Wireless Network Setup interface (other extrapolate)
Intent Intent = new Intent (Android.provider.Settings.ACTION_WIRELESS_SETTINGS);
Startactivityforresult (Intent, 0);
ps:http://www.oschina.net/code/snippet_54100_7587

Full summary of Android Intent usage

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.