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); display map:
- Uri uri = Uri. parse ("geo: 38.899533,-77.036476 ");
- Intent it = new Intent (Intent. Action_VIEW, uri );
- StartActivity (it); 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); call:
Call the dialup Program
- 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 function, you must add it to the configuration file. 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); 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); 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); 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"); add attachments
- 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 program
- Uri uri = Uri. fromParts ("package", strPackageName, null );
- Intent it = new Intent (Intent. ACTION_DELETE, uri );
- StartActivity (it );