Android-intent usage

Source: Internet
Author: User

1. Search for content from Google

Intent intent = new intent ();
Intent. setaction (intent. action_web_search );
Intent. putextra (searchmanager. query, "searchstring ")
Startactivity (intent );


2. Browse the webpage

Uri uri = URI. parse ("http://www.google.com ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );


3. display a map

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


4. Route Planning

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


5. Call

Uri uri = URI. parse ("Tel: xxxxxx ");
Intent it = new intent (intent. action_dial, Uri );
Startactivity (it );


6. Call the SMS Program

Intent it = new intent (intent. action_view );
It. putextra ("sms_body", "the SMS text ");
It. settype ("Vnd. Android-DIR/MMS-SMS ");
Startactivity (it );


7. send SMS

Uri uri = URI. parse ("smsto: 0800000123 ");
Intent it = new intent (intent. action_sendto, Uri );
It. putextra ("sms_body", "the SMS text ");
Startactivity (it );

String body = "this is SMS Demo ";
Intent mmsintent = new intent (intent. action_sendto, Uri. fromparts ("smsto", number, null ));
Mmsintent. putextra (messaging. key_action_sendto_message_body, body );
Mmsintent. putextra (messaging. key_action_sendto_compose_mode, true );
Mmsintent. putextra (messaging. key_action_sendto_exit_on_sent, true );
Startactivity (mmsintent );


8. Send MMS

Uri uri = URI. parse ("content: // media/external/images/Media/23 ");
Intent it = new intent (intent. action_send );
It. putextra ("sms_body", "some text ");
It. putextra (intent. extra_stream, Uri );
It. settype ("image/PNG ");
Startactivity (it );

Stringbuilder sb = new stringbuilder ();
SB. append ("file ://");
SB. append (FD. getabsolutefile ());
Intent intent = new intent (intent. action_sendto, Uri. fromparts ("mmsto", number, null ));
// Below extra datas are all optional.
Intent. putextra (messaging. key_action_sendto_message_subject, subject );
Intent. putextra (messaging. key_action_sendto_message_body, body );
Intent. putextra (messaging. key_action_sendto_content_uri, SB. tostring ());
Intent. putextra (messaging. key_action_sendto_compose_mode, composemode );
Intent. putextra (messaging. key_action_sendto_exit_on_sent, exitonsent );
Startactivity (intent );


9. Send email

Uri uri = URI. parse ("mailto: xxx@abc.com ");
Intent it = new intent (intent. action_sendto, Uri );
Startactivity (it );

Intent it = new intent (intent. action_send );
It. putextra (intent. extra_email, "me@abc.com ");
It. putextra (intent. extra_text, "the email body text ");
It. settype ("text/plain ");
Startactivity (intent. createchooser (IT, "Choose email client "));

Intent it = new intent (intent. action_send );
String [] TOS = {"me@abc.com "};
String [] CCS = {"you@abc.com "};
It. putextra (intent. extra_email, TOS );
It. putextra (intent. extra_cc, CCS );
It. putextra (intent. extra_text, "the email body text ");
It. putextra (intent. extra_subject, "the email subject text ");
It. settype ("message/rfc822 ");
Startactivity (intent. createchooser (IT, "Choose email client "));
Intent it = new intent (intent. action_send );
It. putextra (intent. extra_subject, "the email subject text ");
It. putextra (intent. extra_stream, "file: // sdcard/mysong.mp3 ");
Sendintent. settype ("audio/MP3 ");
Startactivity (intent. createchooser (IT, "Choose email client "));


10. Play multimedia

Intent it = new intent (intent. action_view );
Uri uri = URI. parse ("file: // sdcard/song.mp3 ");
It. setdataandtype (Uri, "audio/MP3 ");
Startactivity (it );

Uri uri = URI. withappendedpath (mediastore. Audio. Media. internal_content_uri, "1 ");
Intent it = new intent (intent. action_view, Uri );
Startactivity (it );


11. Uninstall APK

Uri uri = URI. fromparts ("package", strpackagename, null );
Intent it = new intent (intent. action_delete, Uri );
Startactivity (it );


12. Install APK

Uri installuri = URI. fromparts ("package", "XXX", null );
Returnit = new intent (intent. action_package_added, installuri );


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.