Android: Call and send SMS and intent some other usage

Source: Internet
Author: User

1. Call

You can write your own interface and add the following code to the button's Click event:

Intent Intent = new Intent ();
Intent.setaction ("Android.intent.action.CALL");
Intent.setdata (Uri.parse ("Tel:" + mobile))//mobile is the number you want to dial, the simulator number in the simulator is also available
StartActivity (Intent);

Need to add call permissions:

<uses-permission android:name= "android.permission.CALL_PHONE"/>

2. Send SMS

As with the phone call, add the following code to the button's Click event:

Smsmanager Smsmanager = Smsmanager.getdefault ();
arraylist<string> texts = smsmanager.dividemessage (content);//split SMS, text message too many words to be divided into several times
for (String text:texts) {
Smsmanager.sendtextmessage (mobile, NULL, text, NULL, NULL);//Send SMS, Mobile is the other mobile phone number
}

For should be SMS permissions:

<uses-permissionandroid:name= "android.permission.SEND_SMS"/>



Here are some other examples of intent usages reproduced.

Show Web page
    URI uri = uri.parse ("http://google.com");   
  & nbsp Intent it = new Intent (Intent.action_view, URI);   
    StartActivity (it);

show map
    URI uri = uri.parse ("geo:38.899533,-77.036476"); &NBSP;&NBSP;
    Intent it = new Intent (Intent.action_view, URI);    
& nbsp   StartActivity (IT),    
   //other geo URI examples   &NBSP;
   //GEO:LATITUDE,LONGITUDE&NBSP;&NBSP;
   //GEO:LATITUDE,LONGITUDE?Z=ZOOM&NBSP;&NBSP;
   //geo:0,0 Q=MY+STREET+ADDRESS&NBSP;&NBSP;
   //geo:0,0?q=business+near+city &NBSP;&NBSP;
   //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 it = new Intent (Intent.action_view, URI);
StartActivity (IT);
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 it = new Intent (intent.action_dial, URI);
StartActivity (IT);
//Call out directly
Uri uri = uri.parse ("tel:0800000123");
Intent it = new Intent (Intent.action_call, URI);
StartActivity (IT);
With this, to be in Androidmanifest.xml, plus
<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"));


   //Transmitting accessories
    Intent it = new Intent (intent.action_send);   < BR style= "Line-height:normal;" >     It.putextra (intent.extra_subject, "The email SUBJECT text");  
    It.putextra (Intent.extra_stream, "File:///sdcard/mysong.mp3"); &NBSP;&NBSP;
    Sendintent.settype ("Audio/mp3"); &NBSP;&NBSP;
    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); &NBSP;
       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 Application
        URI uri = uri.fromparts ("Package", Strpackagename, NULL); &NBSP;
        Intent it = new Intent ( Intent.action_delete, URI);    
        StartActivity (it);

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.