Android experience 01 -- intent usage

Source: Internet
Author: User

Reprinted: http://www.android123.com.cn/androidkaifa/612.html

Display web pages:

1. Uri uri = URI. parse ("http://www.android123.com.cn ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Show Google maps:

1. Uri uri = URI. parse ("Geo: 38.899533,-77.036476 ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Maps Path Planning:

1. Uri uri = URI. parse ("http://maps.google.com/maps? F = D & saddr = startlat % 20 startlng & daddr = endlat % 20 endlng & HL = EN ");
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Call number:

1. Uri uri = URI. parse ("Tel: xxxxxx ");
2. Intent it = new intent (intent. action_dial, Uri );
3. startactivity (it );

1. Uri uri = URI. parse ("Tel. xxxxxx ");
2. Intent it = new intent (intent. action_call, Uri );

Note that you need the permission <uses-Permission id = "android. Permission. call_phone"/>

Send SMS/MMS

1. Intent it = new intent (intent. action_view );
2. it. putextra ("sms_body", "Welcome to Android Development Network ");
3. It. settype ("Vnd. Android-DIR/MMS-SMS ");
4. startactivity (it );

Send SMS

1. Uri uri = URI. parse ("smsto: 10086 ");
2. Intent it = new intent (intent. action_sendto, Uri );
3. It. putextra ("sms_body", "10086"); // The body is 10086
4. startactivity (it );

Send MMS

1. uri uri = Uri. parse ("content: // media/external/images/Media/10"); // This URI is modified based on the actual situation. External indicates that external storage is sdcard.
2. Intent it = new intent (intent. action_send );
3. It. putextra ("sms_body", "android123.com.cn ");
4. It. putextra (intent. extra_stream, Uri );
5. It. settype ("image/PNG ");
6. startactivity (it );

Send email

2. Uri uri = URI. parse ("mailto: android123@163.com ");
3. Intent it = new intent (intent. action_sendto, Uri );
4. startactivity (it );

1. Intent it = new intent (intent. action_send );
2. it. putextra (intent. extra_email, "android123@163.com ");
3. It. putextra (intent. extra_text, "android development network test ");
4. It. settype ("text/plain ");
5. startactivity (intent. createchooser (IT, "select an email client "));

1. Intent it = new intent (intent. action_send );
2. String [] TOS = {"android123@163.com"}; // send
3. String [] CCS = {"ophone123@163.com"}; // CC
4. It. putextra (intent. extra_email, TOS );
5. It. putextra (intent. extra_cc, CCS );
6. It. putextra (intent. extra_text, "body ");
7. It. putextra (intent. extra_subject, "title ");
8. It. settype ("message/rfc822"); // encoding type
9. startactivity (intent. createchooser (IT, "select an email client "));

Add attachments by email

1. Intent it = new intent (intent. action_send );
2. it. putextra (intent. extra_subject, "body ");
3. It. putextra (intent. extra_stream, "file: // sdcard/nobody.pdf"); // the attachment is the nobody MP3 file on the SD card.
4. sendintent. settype ("audio/MP3 ");
5. startactivity (intent. createchooser (IT, "select an email client "));

Play multimedia

1.
2. Intent it = new intent (intent. action_view );
3. Uri uri = URI. parse ("file: // sdcard/nobody.mp3 ");
4. It. setdataandtype (Uri, "audio/MP3 ");
5. startactivity (it );

1. Uri uri = URI. withappendedpath (mediastore. Audio. Media. internal_content_uri, "1"); // calls the play from the mediaprovider index in the system
2. Intent it = new intent (intent. action_view, Uri );
3. startactivity (it );

Uninstall uninstall the program

1. Uri uri = URI. fromparts ("package", packagename, null); // packagenameis the package name, such as com.android123.apk Installer
2. Intent it = new intent (intent. action_delete, Uri );
3. startactivity (it );

Enter the contact page

  1. Intent intent = new intent ();
  2. Intent. setaction (intent. action_view );
  3. Intent. setdata (people. content_uri );
  4. Startactivity (intent );

 View a contact. Of course, this is action_view. If you select and change the Return Action to action_pick, startactivityforresult is required for intent processing.

  1. Uri personuri = contenturis. withappendedid (people. content_uri, ID); // The last Id parameter is the database baseid in the contact provider, that is, the row
  2.  Intent intent = new intent ();
  3.  Intent. setaction (intent. action_view );
  4.  Intent. setdata (personuri );
  5. Startactivity (intent );

 Select an image

  1. Intent intent = newintent (intent. action_get_content );
  2. Intent. addcategory (intent. category_openable );
  3. Intent. settype ("image google_ad_slot = \" 5506163105 \ "; google_ad_width = 468; google_ad_height = 60 ;);

It is relatively simple to download the APK and install it on your own, but it clearly shows the Android platform's implicit intent. The general applications installed on the underlying system use the System Service packageinstaller to identify the intent for program installation.

  1. Intent intent = new intent (intent. action_view );
  2. Intent. setdataandtype (URI. parse ("file: //" + "/sdcard/android123.com/cwj.apk", "application/vnd. Android. Package-Archive ");
  3. Startactivity (intent );

The packageinstaller service will internally match the MIME type as application/vnd. android. the intent of package-archive, which indicates that the first parameter of setdataandtype is uri. In fact, the string inside the URI corresponds to file: // with the regular path, of course, other URI construction methods can also be uri. fromfile (new file (sfilefullpath )).

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.