Android Intent Exploration

Source: Internet
Author: User

An Android application consists of four components (Activity, Broadcast, Service, and ContentProvider), which are independent, they can call and coordinate each other to form a real Android Application. The communication between these components is mainly completed with Intent assistance.

Intent describes the actions, actions involving data, and additional data of an application. Android identifies the corresponding components based on the description of the Intent, pass Intent to the called component and complete the call of the component.

Therefore, Intent acts as a media intermediary here, providing information about component calls to each other to decouple callers from callers.

For example, in an application maintained by a contact, when we click a contact on a contact list screen (assuming the corresponding Activity is ListActivity, to jump out of the contact's detail screen (assuming the corresponding Activity is DetailActivity), ListActivity needs to construct an Intent, which is used to tell the system, we need to perform the "View" action. The object corresponding to this action is "a contact". Then, call startActivity (Intent intent) to pass in the constructed Intent, the system will go to AndroidManifest according to the description in this Intent. if an Activity that meets the Intent requirement is found in xml, the system will call the Activity found, that is, DetailActivity, and finally pass in Intent. DetailActivity will execute the corresponding operation according to the description in this Intent.

Display webpage
Uri uri = Uri. parse ("http://www.google.com.hk /");
Intent intent = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (intent );


Show Map
Uri uri = Uri. parse ("geo: 38.899533,-77.036476 ");
Intent intent = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (intent );
// Other geo URI examples (latitude: latitude, longpolling: longitude)
// Geo: latitude, longpolling
// Geo: latitude, longpolling? Z = zoom
// Geo: 0, 0? Q = my + street + address
// Geo: 0, 0? Q = business + near + city
// Google. streetview: cbll = lat, lng & white = 1, yaw, pitch, zoom & mz = mapZoom



Route Planning
Uri uri = Uri. parse ("http://maps.google.com/maps? F = d & saddr = startLat % 20 startLng & daddr = endLat % 20 endLng & hl = en ");
Intent intent = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (intent );
// Where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456


Call
// Call the dialing program
Uri uri = Uri. parse ("tel: 0800000123 ");
Intent intent = new Intent (Intent. ACTION_DIAL, uri );
StartActivity (intent );

// Directly call out
Uri uri = Uri. parse ("tel: 0800000123 ");
Intent intent = new Intent (Intent. ACTION_CALL, uri );
StartActivity (intent );
// Add <uses-permission id = "android. permission. CALL_PHONE"/> to AndroidManifest. xml.

Send SMS/MMS
// Call the SMS Program
Intent it = new Intent (Intent. ACTION_VIEW, uri );
It. putExtra ("sms_body", "The SMS text ");
It. setType ("vnd. android-dir/mms-sms ");
StartActivity (it );

// Send messages
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 "));

// Transfer 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
Uri uri = Uri. parse ("file: // sdcard/song.mp3 ");
Intent it = new Intent (Intent. ACTION_VIEW, uri );
It. setType ("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 );


Market Problems
// Search for an 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 information about an application
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

Uninstall Application
Uri uri = Uri. fromParts ("package", strPackageName, null );
Intent it = new Intent (Intent. ACTION_DELETE, uri );
StartActivity (it );
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.