Android Intent usage

Source: Internet
Author: User
Do not forget to start a new Activity from BroadcastReceiver. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); public class MyReceiver extends BroadcastReceiver {public static final String action = "acc"; public void onReceive (Context context, Intent intent) {Intent I = new Intent (context, Receivered. class); I. setFlags (Intent. FLAG_ACTIVITY_NEW_TASK); context. startActivity (I) ;}} 1. specify action and type // SIM importIntent = new I Ntent (Intent. ACTION_VIEW); importIntent. setType ("vnd. android. cursor. item/sim-contact "); importIntent. setClassName ("com. android. phone "," com. android. phone. simContacts "); menu. add (0, 0, 0, R. string. importFromSim ). setIcon (R. drawable. ic_menu_import_contact ). setIntent (importIntent); 2. specify act ion, da ta, and type (1) for implicit search of type sample code: uri: content: // simcontacts/simPeople/(id) intent = new Intent ("android. intent. action. S IMEDIT ", uri); startActivity (intent); the program searches for getType () case SIM_PEOPLE_ID: return" vnd. android. cursor. item/sim-contact "; the filter in the configuration file sets AndroidManifest. xml <intent-filter> <action android: name = "android. intent. action. SIMEDIT "/> <category android: name =" android. intent. category. DEFAULT "/> <data android: mimeType =" vnd. android. cursor. item/sim-contact "/> </intent-filter> You can also set the type, However, you can only use setDataAndType () 3. other intent setComponent (ComponentName component) Intent setClassName (Context packageContext, String className) Intent setClassName (String packageName, String className) Intent setClass (Context packageContext, Class <?> Cls) 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 following lists the usage of several Intent display webpages: 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 = dsaddr = startLat % 20 startLng & daddr = endLat % 20 endLng & hl = en "); Intent it = new Intent (Intent. ACTION_VIEW, URI); startActivity (it); call the dialing program 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); you must add <uses-permission id = "android. permission. CALL_PHONE "/> send SMS/MMS call send 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); send sms Uri = uri. parse ("Maid: 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_S END); it. putExtra ("sms_body", "some text"); it. putExtra (Intent. EXTRA_STREAM, uri); it. setType ("image/png"); startActivity (it); send EmailUri 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/p Lain "); 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 (Inte Nt. createChooser (it, "Choose Email Client"); Add 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/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. mp 3 "); 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); uninstall apkUri uninstallUri = Uri. fromParts ("package "," Xxx ", null); returnIt = new Intent (Intent. ACTION_DELETE, uninstallUri); install apkUri installUri = Uri. fromParts ("package", "xxx", null); returnIt = new Intent (Intent. ACTION_PACKAGE_ADDED, installUri); play audioUri playUri = Uri. parse ("file: // sdcard/download/everythinghistory"); returnIt = new Intent (Intent. ACTION_VIEW, playUri); // sends 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 application 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 support, app_id not 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
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.