Summary of Android Intent usage

Source: Internet
Author: User

Intent is something special in Android. You can specify the action (such as view, edit, and dial) to be executed by the program in Intent and the information required when the program executes the action. After startActivity () is called, the Android system will automatically find the application that best meets your specified requirements and execute the application.

The usage of several Intent types is listed below
Display webpage:

  1. Uri uri = Uri. parse ("http://www.google.com ");
  2. Intent it = new Intent (Intent. ACTION_VIEW, uri );
  3. StartActivity (it); display map:
    1. Uri uri = Uri. parse ("geo: 38.899533,-77.036476 ");
    2. Intent it = new Intent (Intent. Action_VIEW, uri );
    3. StartActivity (it); 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:
        Call the dialup Program
        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 );
          3. To use this function, you must add it to the configuration file. Send SMS/MMS
            Call the program for sending text messages
            1. Intent it = new Intent (Intent. ACTION_VIEW );
            2. It. putExtra ("sms_body", "The SMS text ");
            3. It. setType ("vnd. android-dir/mms-sms ");
            4. StartActivity (it); send SMS
              1. Uri uri = Uri. parse ("smsto: 0800000123 ");
              2. Intent it = new Intent (Intent. ACTION_SENDTO, uri );
              3. It. putExtra ("sms_body", "The SMS text ");
              4. StartActivity (it); send MMS
                1. Uri uri = Uri. parse ("content: // media/external/images/media/23 ");
                2. Intent it = new Intent (Intent. ACTION_SEND );
                3. It. putExtra ("sms_body", "some text ");
                4. It. putExtra (Intent. EXTRA_STREAM, uri );
                5. It. setType ("image/png ");
                6. StartActivity (it); send Email
                  1. Uri uri = Uri. parse ("mailto: xxx@abc.com ");
                  2. Intent it = new Intent (Intent. ACTION_SENDTO, uri );
                  3. StartActivity (it );
                    1. Intent it = new Intent (Intent. ACTION_SEND );
                    2. It. putExtra (Intent. EXTRA_EMAIL, "me@abc.com ");
                    3. It. putExtra (Intent. EXTRA_TEXT, "The email body text ");
                    4. It. setType ("text/plain ");
                    5. StartActivity (Intent. createChooser (it, "Choose Email Client "));
                      1. Intent it = new Intent (Intent. ACTION_SEND );
                      2. String [] tos = {"me@abc.com "};
                      3. String [] ccs = {"you@abc.com "};
                      4. It. putExtra (Intent. EXTRA_EMAIL, tos );
                      5. It. putExtra (Intent. EXTRA_CC, ccs );
                      6. It. putExtra (Intent. EXTRA_TEXT, "The email body text ");
                      7. It. putExtra (Intent. EXTRA_SUBJECT, "The email subject text ");
                      8. It. setType ("message/rfc822 ");
                      9. StartActivity (Intent. createChooser (it, "Choose Email Client"); add attachments
                        1. Intent it = new Intent (Intent. ACTION_SEND );
                        2. It. putExtra (Intent. EXTRA_SUBJECT, "The email subject text ");
                        3. It. putExtra (Intent. EXTRA_STREAM, "file: // sdcard/mysong.mp3 ");
                        4. SendIntent. setType ("audio/mp3 ");
                        5. StartActivity (Intent. createChooser (it, "Choose Email Client"); play multimedia
                          1. Intent it = new Intent (Intent. ACTION_VIEW );
                          2. Uri uri = Uri. parse ("file: // sdcard/song.mp3 ");
                          3. It. setDataAndType (uri, "audio/mp3 ");
                          4. StartActivity (it );
                            1. Uri uri = Uri. withAppendedPath (MediaStore. Audio. Media. INTERNAL_CONTENT_URI, "1 ");
                            2. Intent it = new Intent (Intent. ACTION_VIEW, uri );
                            3. StartActivity (it); Uninstall program
                              1. Uri uri = Uri. fromParts ("package", strPackageName, null );
                              2. Intent it = new Intent (Intent. ACTION_DELETE, uri );
                              3. StartActivity (it );

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.