Complete summary of Android Intent usage and example code _android

Source: Internet
Author: User

1. Call Dialing Program

To mobile service 10086 call
uri uri = uri.parse ("tel:10086");
Intent Intent = new Intent (intent.action_dial, URI);
StartActivity (Intent);

2. Send SMS or MMS

Send 10086 sms
uri uri = uri.parse ("smsto:10086") with content "Hello";
Intent Intent = new Intent (intent.action_sendto, URI);
Intent.putextra ("Sms_body", "Hello");
StartActivity (intent);
Send MMS (equivalent to send SMS with attachment)
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);

3. Open Web page through browser

Open the Google homepage
uri uri = uri.parse ("http://www.google.com");
Intent Intent = new Intent (Intent.action_view, URI);
StartActivity (Intent);

4. Send email

//Send mail uri uri = uri.parse (" mailto:someone@domain.com ") to someone@domain.com;
Intent Intent = new Intent (intent.action_sendto, URI);
StartActivity (Intent);
Send mail to someone@domain.com Intent Intent = new Intent (intent.action_send) with the content "Hello";
Intent.putextra (Intent.extra_email, "someone@domain.com");
Intent.putextra (Intent.extra_subject, "SUBJECT");
Intent.putextra (Intent.extra_text, "Hello");
Intent.settype ("Text/plain");
StartActivity (Intent);
Email Intent intent=new Intent (intent.action_send) to multiple people; String[] tos = {"1@abc.com", "2@abc.com"}; Recipient string[] CCS = {"3@abc.com", "4@abc.com"}; CC string[] BCCs = {"5@abc.com", "6@abc.com"};
Dense send 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); 

5. Display map and path planning

Open Google Map 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, east longitude 116.3) to Shanghai somewhere (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);

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

7. Take photos

Open the camera program
Intent Intent = new Intent (mediastore.action_image_capture); 
Startactivityforresult (Intent, 0);
Take out the photo data
Bundle extras = Intent.getextras (); 
Bitmap Bitmap = (Bitmap) extras.get ("Data");

8. Get and cut pictures

Get and cut the picture Intent Intent = new Intent (intent.action_get_content);
Intent.settype ("image/*"); Intent.putextra ("Crop", "true"); Open Shear Intent.putextra ("Aspectx", 1);
The shear width-height ratio 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 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 shear width-height ratio 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);

9. Open Google Market

Open Google market directly into the program's detailed page
uri uri = uri.parse ("market://details?id=" + "Com.demo.app");
Intent Intent = new Intent (Intent.action_view, URI);
StartActivity (Intent);

10. Installation and Uninstall procedures

Uri uri = uri.fromparts ("package", "Com.demo.app", null); 
Intent Intent = new Intent (Intent.action_delete, URI); 
StartActivity (Intent);

11. Enter the Setup interface

Enter the wireless network Setup interface (others can be extrapolate) 
Intent Intent = new Intent (Android.provider.Settings.ACTION_WIRELESS_SETTINGS); 
Startactivityforresult (Intent, 0);

The above is to the Android Intent data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!

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.