A comprehensive summary of several ways to use Android intent

Source: Internet
Author: User

Intent should be something peculiar to Android. You can specify the actions that the program will run in intent (for example: view,edit,dial), and the data that the program needs to run to that action. When all is specified, just call StartActivity () and the Android system will proactively look for the application that best meets your requirements and run the program.

The following is a list of how several Intent are used to display Web pages: URI uri = uri.parse ("http://www.google.com"); Intent it  
Path planning: Uri uri = Uri.parse ("Http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng &hl=en "); Intent it = new Intent (Intent.action_view,uri); startactivity (it);
Dial number:
Call the dialer URI uri = uri.parse ("tel:xxxxxx"); Intent it = new Intent (intent.action_dial, URI);  StartActivity (it);  Uri uri = uri.parse ("tel.xxxxxx"); Intent it =new Intent (Intent.action_call,uri); To use this, you must add the <uses-permission ID in the config file. = "Android.permission.CALL_PHONE"/
Send Sms/mms
Call the program that sends the SMS Intent it = new Intent (intent.action_view);   It.putextra ("Sms_body", "The SMS Text");   It.settype ("vnd.android-dir/mms-sms");   StartActivity (IT);  
Send sms URI uri = uri.parse ("smsto:0800000123");   Intent it = new Intent (intent.action_sendto, URI);   It.putextra ("Sms_body", "The SMS Text");   
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");   
Send Emailuri uri = Uri.parse ("Mailto:[email protected]"); Intent it = new Intent (intent.action_sendto, URI); StartActivity ( IT);
Intent it = new Intent (intent.action_send);   It.putextra (Intent.extra_email, "[EMAIL protected]");   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={"[Email protected]"};     
String[]     Ccs={"[email protected]"};     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"));   Add Attachment 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"); 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);  
Uninstall uri uri = uri.fromparts ("package", strpackagename, null);   Intent it = new Intent (Intent.action_delete, URI);   StartActivity (IT);

Install APK

    1. Uri Installuri = uri.fromparts ("package", "XXX", null);

2.returnIt = new Intent (intent.action_package_added, Installuri);

Play Audio

    1. Uri Playuri = Uri.parse ("File:///sdcard/download/everything.mp3");

    2. Returnit = new Intent (Intent.action_view, Playuri);

Send 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/eoe.mp3");
    4. Sendintent.settype ("Audio/mp3");
    5. StartActivity (Intent.createchooser (it, "Choose Email Client"));

Market related

Search for Apps
Uri uri = uri.parse ("Market://search?q=pname:pkg_name");
Intent it = new Intent (Intent.action_view, URI);
StartActivity (IT);
Where Pkg_name is the full package path for an application

Displays the specific page for the specified application (this does not seem to support the app_id)
Uri uri = uri.parse ("market://details?id=app_id");
Intent it = new Intent (Intent.action_view, URI);
StartActivity (IT);
Where app_id is the application ID, find the ID
By clicking on your application in market home
page, and notice the ID from the address bar

Intent Intent = new Intent ();
Intent.setaction (Intent.action_web_search);
Intent.putextra (Searchmanager.query, "searchstring")
StartActivity (Intent);

A comprehensive summary of several ways to use Android intent

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.