Explore the intent of Android

Source: Internet
Author: User

In an Android application, consisting of four components (four components: Activity, broadcast, Service, ContentProvider), and these four components are independent, they can be called each other, coordinated work, Eventually form a real Android app. In the communication between these components, mainly by the intent assistance to complete.

Intent is responsible for the action of an operation in the application, the action involves data, the additional data is described, Android according to this intent description, is responsible to find the corresponding component, the intent passed to the calling component, and complete the call of the component.

As a result, intent plays a role as a media intermediary, specifically providing information about the components that are called to each other, and decoupling the caller from the callee.

For example, in a contact maintenance app, when we click on a contact in a contact List screen (assuming the corresponding activity is listactivity), Want to be able to jump out of this contact's details screen (assuming the corresponding activity is detailactivity) in order to achieve this, listactivity needs to construct a intent, which is used to tell the system that we want to do a "view" action, This action corresponds to the View object is "a contact", and then call StartActivity (Intent Intent), the constructed Intent incoming, the system will be based on the description in this Intent, To find the activity that satisfies this intent requirement in Androidmanifest.xml, the system invokes the found activity, which is detailactivity, and the final incoming intent,detailactivity is executed according to the description in this intent. The appropriate action.

Show Web page
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);
Example of other Geo URIs (Latitude: Latitude, Longitude: longitude)
Geo:latitude,longitude
Geo:latitude,longitude?z=zoom
Geo:0,0?q=my+street+address
Geo:0,0?q=business+near+city
Google.streetview:cbll=lat,lng&cbp=1,yaw,,pitch,zoom&mz=mapzoom

Path planning
Uri uri = Uri.parse ("http://maps.google.com/maps?f=d&saddr=startlat%20startlng&daddr=endlat%20endlng& Hl=en ");
Intent Intent = new Intent (Intent.action_view, URI);
StartActivity (Intent);
Where Startlat, STARTLNG, Endlat, ENDLNG is a long with 6 decimals like:50.123456

Call
Call out Dialer
Uri uri = uri.parse ("tel:0800000123");
Intent Intent = new Intent (intent.action_dial, URI);
StartActivity (Intent);

Just call out.
Uri uri = uri.parse ("tel:0800000123");
Intent Intent = new Intent (Intent.action_call, URI);
StartActivity (Intent);
With this, in Androidmanifest.xml, add <uses-permission id= "Android.permission.CALL_PHONE"/>

Transfer Sms/mms
Call 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 Message
Uri uri = uri.parse ("smsto://0800000123");
Intent it = new Intent (intent.action_sendto, URI);
It.putextra ("Sms_body", "The SMS Text");
StartActivity (IT);

Transfer 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:[email protected]");
Intent it = new Intent (intent.action_sendto, URI);
StartActivity (IT);

Intent it = new Intent (intent.action_send);
It.putextra (Intent.extra_email, "[EMAIL protected]");
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={"[Email protected]"};
String[] ccs={"[Email protected]"};
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 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
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 related
Find an App
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

Show information about an app
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 in market home
page, and notice the ID from the address bar

Uninstall applications
Uri uri = uri.fromparts ("package", strpackagename, NULL);
Intent it = new Intent (Intent.action_delete, URI);
StartActivity (IT);

Explore the intent of Android

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.