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:
- Uri uri = URI. parse ("http://www.google.com ");
- Intent it = new intent (intent. action_view, Uri );
- Startactivity (it );
Copy code Display map:
- Uri uri = URI. parse ("Geo: 38.899533,-77.036476 ");
- Intent it = new intent (intent. action_view, Uri );
- Startactivity (it );
Copy code Path Planning:
- Uri uri = URI. parse ("http://maps.google.com/maps? F = D & saddr = startlat % 20 startlng & daddr = endlat % 20 endlng & HL = EN ");
- Intent it = new intent (intent. action_view, Uri );
- Startactivity (it );
Copy code Call number: Call the dialup Program
- Uri uri = URI. parse ("Tel: xxxxxx ");
- Intent it = new intent (intent. action_dial, Uri );
- Startactivity (it );
Copy code
- Uri uri = URI. parse ("Tel. xxxxxx ");
- Intent it = new intent (intent. action_call, Uri );
- 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
- Intent it = new intent (intent. action_view );
- It. putextra ("sms_body", "the SMS text ");
- It. settype ("Vnd. Android-DIR/MMS-SMS ");
- 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
- Uri uri = URI. parse ("smsto: 0800000123 ");
- Intent it = new intent (intent. action_sendto, Uri );
- It. putextra ("sms_body", "the SMS text ");
- Startactivity (it );
Copy code 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 );
Copy code Send email
- Uri uri = URI. parse ("mailto: xxx@abc.com ");
- Intent it = new intent (intent. action_sendto, Uri );
- Startactivity (it );
Copy code
- 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 "));
Copy code
- 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 "));
Copy code 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 "));
Copy code Play multimedia
- Intent it = new intent (intent. action_view );
- Uri uri = URI. parse ("file: // sdcard/song.mp3 ");
- It. setdataandtype (Uri, "audio/MP3 ");
- Startactivity (it );
Copy code
- Uri uri = URI. withappendedpath (mediastore. Audio. Media. internal_content_uri, "1 ");
- Intent it = new intent (intent. action_view, Uri );
- Startactivity (it );
Copy code Uninstall program
- Uri uri = URI. fromparts ("package", strpackagename, null );
- Intent it = new intent (intent. action_delete, Uri );
- Startactivity (it );
Copy code |
Uninstall APK
- Uri uninstalluri = URI. fromparts ("package", "XXX", null );
- Returnit = new intent (intent. action_delete, uninstalluri );
Copy code
Install APK
- Uri installuri = URI. fromparts ("package", "XXX", null );
- Returnit = new intent (intent. action_package_added, installuri );
Copy code
Play audio
- Uri playuri = URI. parse ("file: // sdcard/download/everything.mp3 ");
- Returnit = new intent (intent. action_view, playuri );
Copy code
- // Send the attachment
- Intent it = new intent (intent. action_send );
- It. putextra (intent. extra_subject, "the email subject text ");
- It. putextra (intent. extra_stream, "file: // sdcard/eoe.mp3 ");
- Sendintent. settype ("audio/MP3 ");
- Startactivity (intent. createchooser (IT, "Choose email client "));
- // Search for Applications
- 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
- // Display the detailed page of the specified application (this does not seem to be supported and app_id cannot be found)
- 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 on market Home
- // 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