Summary of Android intent usage

Source: Internet
Author: User
Intent It should be something special in Android. You can specify Program The action to be executed (such as view, edit, dial), and Materials . After all settings are specified, you only need to call startactivity (), Android System Will automatically find the most suitable for your specified requirements Application Program, and execute the program.

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 number:
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 configureFile<Uses-Permission id ="Android. Permission. call_phone "/>

Send SMS/MMS
Send callSMSProgram

    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 attachment

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

PlayMultimedia

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

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.