Use of Android intent

Source: Internet
Author: User
The usage of Android intent is summarized comprehensively.
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 );

Copy code

Display map:

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

Copy code

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

Copy code

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

Copy code

  1. Uri uri = URI. parse ("Tel. xxxxxx ");
  2. Intent it = new intent (intent. action_call, Uri );
  3. To use this function, you must add <uses-Permission id = "android. Permission. call_phone"/> to the configuration file.

Copy code

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 );
Copy code
Send Group messages (Separate multiple numbers by commas)

Mobile = "1890000000; 1890000001 ";

Intent intent = new intent (intent. action_view );

Intent. putextra ("Address", mobile );

// Intent. putextra ("sms_body", "I am Joe! ");

Intent. settype ("Vnd. Android-DIR/MMS-SMS ");

Startactivity (intent );

 

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

Copy code

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

Copy code

Send email

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

Copy code

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

Copy code

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

Copy code

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

Copy code

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

Copy code

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

Copy code

Uninstall program

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

Copy code

Uninstall APK

  1. Uri uninstalluri = URI. fromparts ("package", "XXX", null );
  2. Returnit = new intent (intent. action_delete, uninstalluri );

Copy code

Install APK

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

Copy code

Play audio

  1. Uri playuri = URI. parse ("file: // sdcard/download/everything.mp3 ");
  2. Returnit = new intent (intent. action_view, playuri );

Copy code

  1. // Send the attachment
  2. Intent it = new intent (intent. action_send );
  3. It. putextra (intent. extra_subject, "the email subject text ");
  4. It. putextra (intent. extra_stream, "file: // sdcard/eoe.mp3 ");
  5. Sendintent. settype ("audio/MP3 ");
  6. Startactivity (intent. createchooser (IT, "Choose email client "));
  1. // Search for Applications
  2. Uri uri = URI. parse ("Market: // search? Q = pname: pkg_name ");
  3. Intent it = new intent (intent. action_view, Uri );
  4. Startactivity (it );
  5. // Where pkg_name is the full package path for an application
  6. // Display the detailed page of the specified application (this does not seem to be supported and app_id cannot be found)
  7. Uri uri = URI. parse ("Market: // details? Id = app_id ");
  8. Intent it = new intent (intent. action_view, Uri );
  9. Startactivity (it );
  10. // Where app_id is the Application ID, find the ID
  11. // By clicking on your application on market Home
  12. // Page, and notice the ID from the address bar
/**
* Get the package to install intent
* @ Param tempfile
* @ Return
*/
Public static intent getpackageinstallintent (File tempfile)
{
Uri mpackageuri = URI. fromfile (tempfile );
Intent in = new intent ();
In. setaction (intent. action_view );
In. addcategory (intent. category_default );
In
. Setcomponent (New componentname (
"Com. Android. packageinstaller ",
"Com. Android. packageinstaller. packageinstalleractivity "));
In. setdataandtype (mpackageuri,
"Application/vnd. Android. Package-Archive ");
In. setflags (intent. flag_activity_new_task );
Return in;
}

---------------------------------------------------------

Conversion from: Use of Android intent

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.