Androud's most useful Intent

Source: Internet
Author: User

[Code] Call the dialup Program
 
1 // call mobile customer service 10086

2 Uri uri = Uri. parse ("tel: 10086 ");

3 Intent intent = new Intent (Intent. ACTION_DIAL, uri );

4 startActivity (intent );

[Code] send SMS or MMS
 
01 // send a "Hello" text message to 10086

02 Uri uri = Uri. parse ("smsto: 10086 ");

03 Intent intent = new Intent (Intent. ACTION_SENDTO, uri );

04 intent. putExtra ("sms_body", "Hello ");

05 startActivity (intent );

06 // send MMS (equivalent to sending an SMS with an attachment)

07 Intent intent = new Intent (Intent. ACTION_SEND );

08 intent. putExtra ("sms_body", "Hello ");

09 Uri uri = Uri. parse ("content: // media/external/images/media/23 ");

10 intent. putExtra (Intent. EXTRA_STREAM, uri );

11 intent. setType ("image/png ");

12 startActivity (intent );

[Code] Open a webpage through a browser
 
1 // open the Google Homepage

2 Uri uri = Uri. parse ("http://www.google.com ");

3 Intent intent = new Intent (Intent. ACTION_VIEW, uri );

4 startActivity (intent );

[Code] Send email
 
01 // send email to someone@domain.com

02 Uri uri = Uri. parse ("mailto: someone@domain.com ");

03 Intent intent = new Intent (Intent. ACTION_SENDTO, uri );

04 startActivity (intent );

05 // send an email with the content "Hello" to the someone@domain.com

06 Intent intent = new Intent (Intent. ACTION_SEND );

07 intent. putExtra (Intent. EXTRA_EMAIL, "someone@domain.com ");

08 intent. putExtra (Intent. EXTRA_SUBJECT, "Subject ");

09 intent. putExtra (Intent. EXTRA_TEXT, "Hello ");

10 intent. setType ("text/plain ");

11 startActivity (intent );

12 // send emails to multiple users

13 Intent intent = new Intent (Intent. ACTION_SEND );

14 String [] tos = {"1@abc.com", "2@abc.com"}; // recipient

15 String [] ccs = {"3@abc.com", "4@abc.com"}; // CC

16 String [] bccs = {"5@abc.com", "6@abc.com"}; // BCC

17 intent. putExtra (Intent. EXTRA_EMAIL, tos );

18 intent. putExtra (Intent. EXTRA_CC, ccs );

19 intent. putExtra (Intent. EXTRA_BCC, bccs );

20 intent. putExtra (Intent. EXTRA_SUBJECT, "Subject ");

21 intent. putExtra (Intent. EXTRA_TEXT, "Hello ");

22 intent. setType ("message/rfc822 ");

23 startActivity (intent );

[Code] display map and Path Planning
 
1 // open Google map China's Beijing location (latitude 39.9, longitude 116.3)

2 Uri uri = Uri. parse ("geo: 39.9, 116.3 ");

3 Intent intent = new Intent (Intent. ACTION_VIEW, uri );

4 startActivity (intent );

5 // Route Planning: from a certain place in Beijing (north latitude 39.9, east longitude 116.3) to a certain place in Shanghai (north latitude 31.2, east longitude 121.4)

6 Uri uri = Uri. parse ("http://maps.google.com/maps? F = d & saddr = 39.9 116.3 & daddr = 31.2 121.4 ");

7 Intent intent = new Intent (Intent. ACTION_VIEW, uri );

8 startActivity (intent );

[Code] Play multimedia
 
1 Intent intent = new Intent (Intent. ACTION_VIEW );

2 Uri uri = Uri. parse ("file: // sdcard/foodie ");

3 intent. setDataAndType (uri, "audio/mp3 ");

4 startActivity (intent );

5

6 Uri uri = Uri. withAppendedPath (MediaStore. Audio. Media. INTERNAL_CONTENT_URI, "1 ");

7 Intent intent = new Intent (Intent. ACTION_VIEW, uri );

8 startActivity (intent );

[Code] photographing
 
1 // open the camera program

2 Intent intent = new Intent (MediaStore. ACTION_IMAGE_CAPTURE );

3 startActivityForResult (intent, 0 );

4 // retrieve Photo Data

5 Bundle extras = intent. getExtras ();

6 Bitmap bitmap = (Bitmap) extras. get ("data ");

[Code] Get and cut an image
 
01 // obtain and cut the image

02 Intent intent = new Intent (Intent. ACTION_GET_CONTENT );

03 intent. setType ("image /*");

04 intent. putExtra ("crop", "true"); // enable cut

05 intent. putExtra ("aspectX", 1); // the aspect ratio of the cut is.

06 intent. putExtra ("aspectY", 2 );

07 intent. putExtra ("outputX", 20); // Save the width and height of the image

08 intent. putExtra ("outputY", 40 );

09 intent. putExtra ("output", Uri. fromFile (new File ("/mnt/sdcard/temp"); // save path

10 intent. putExtra ("outputFormat", "JPEG"); // return format

11 startActivityForResult (intent, 0 );

12 // cut a specific image

13 Intent intent = new Intent ("com. android. camera. action. CROP ");

14 intent. setClassName ("com. android. camera", "com. android. camera. CropImage ");

15 intent. setData (Uri. fromFile (new File ("/mnt/sdcard/temp ")));

16 intent. putExtra ("outputX", 1); // the aspect ratio of the cut is.

17 intent. putExtra ("outputY", 2 );

18 intent. putExtra ("aspectX", 20); // Save the width and height of the image

19 intent. putExtra ("aspectY", 40 );

20 intent. putExtra ("scale", true );

21 intent. putExtra ("noFaceDetection", true );

22 intent. putExtra ("output", Uri. parse ("file: // mnt/sdcard/temp "));

23 startActivityForResult (intent, 0 );

[Code] Open Google Market
 
1 // Open Google Market and directly go to the detailed page of the program

2 Uri uri = Uri. parse ("market: // details? Id = "+" com. demo. app ");

3 Intent intent = new Intent (Intent. ACTION_VIEW, uri );

4 startActivity (intent );

[Code] install and uninstall a program
 
1 Uri uri = Uri. fromParts ("package", "com. demo. app", null );

2 Intent intent = new Intent (Intent. ACTION_DELETE, uri );

3 startActivity (intent );

[Code] Go to the settings page
 
1 // enter the wireless network settings page (you can refer to the other steps)

2 Intent intent = new Intent (android. provider. Settings. ACTION_WIRELESS_SETTINGS );

3

Author: liao3838554
 

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.