Android Send SMS

Source: Internet
Author: User

650) this.width=650; "title=" 8Z) tj61j% $JH 8P) $0[o (}ut.png "src=" http://s2.51cto.com/wyfs02/M00/7E/58/ Wkiom1b83z3tvyi7aaacjsyfemu317.png "alt=" Wkiom1b83z3tvyi7aaacjsyfemu317.png "/> First do the layout and then" send "to do the Click event as follows:

String phonenumber = editphone.gettext (). toString (). Trim (); String message = editmessage.gettext (). toString (). Trim (); Sendsms (phonenumber,message);   private void sendsms (string phonenumber, string message)  {   string sent_sms_action= "Sent_sms_action";  string delivered_sms_action =  " Delivered_sms_action ";     sendintent = new intent (SENT_SMS_ACTION);   deliverintent = new intent (delivered_sms_action);     //returns the status of the Send      sentpi = pendingintent.getbroadcast (this, 0, sendintent,   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;0);            this.registerreceiver (new  Broadcastreceiver ()  {                @Override                 public void onreceive (context _context, intent _intent)   {                    switch  (Getresultcode ())  {                    case Activity.RESULT_OK:                         Toast.maketext (mainactivity.this,                     "SMS sent successfully",  toast.length_short)                     .show ();                        editphone.settext ("" );                      editmessage.settext ("");                  break;                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:                    break;                     case SmsManager.RESULT_ERROR_RADIO_OFF:                    break;                    case smsmanager.result_error_null_pdu:                    break;                    }                }            }, new intentfilter (SENT_SMS_ACTION));                    // Returns the Received status          deliverpi = pendingintent.getbroadcast ( this, 0,                    deliverintent, 0);             this.registerreceiver (nEw broadcastreceiver ()  {                 @Override                 public void onreceive (context _context, intent _intent)  {                     Toast.maketext (mainactivity.this,                "Recipient has successfully received",  toast.length_short)                .show ();                }            }, new  Intentfilter (delivered_sms_action))       //Send SMS   SmsManager  Smsmanager =smsmanager.getdefault (); &nbSp; arraylist<string> dividemessage = smsmanager.dividemessage (message);   for (String text:dividemessage) {   smsmanager.sendtextmessage (phonenumber, null,  TEXT,&NBSP;SENTPI,&NBSP;DELIVERPI);   } }

This is good, and finally don't forget the permissions to configure SMS in the manifest file

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

Android Send SMS

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.