Full summary of Android Intent usage

Source: Internet
Author: User

http://www.oschina.net/code/snippet_54100_7587#12077

[1]. Code calling a dial-up program

1

2

3

4

10086 Call to mobile customer service

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

Intent Intent = new Intent (intent.action_dial, URI);

StartActivity (Intent);

[2]. Code Send sms or MMS

1

2

3

4

5

6

7

8

9

10

11

12

//to 10086 Send Message "Hello" for text messages

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

[3]. Code Open a Web page through a browser

1

2

3

4

Open Google home page

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

Intent Intent = new Intent (Intent.action_view, URI);

StartActivity (Intent);

[4]. Code Send e-mail

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

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

[5]. Code Show map and path planning

1

2

3

4

5

6

7

8

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

[6]. Code Play Multimedia

1

2

3

4

5

6

7

8

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]. Code take pictures

1

2

3

4

5

6

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

[8]. Code Get and cut a picture

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21st

22

23

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

[9]. Code Open Google Market

1

2

3

4

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

[ten]. Code Installing and uninstalling programs

1

2

3

Uri uri = uri.fromparts ("package", "Com.demo.app", null);

Intent Intent = new Intent (Intent.action_delete, URI);

StartActivity (Intent);

[One by one ]. Code Enter the setup screen

1

2

3

Access to the Wireless Network Setup interface (other extrapolate)

Intent Intent = new Intent (Android.provider.Settings.ACTION_WIRELESS_SETTINGS);

Startactivityforresult (Intent, 0);

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.