--smsmanager of system services provided by Android (SMS manager)

Source: Internet
Author: User

--smsmanager of system services provided by Android (SMS manager)

--Reprint Please specify Source: Coder-pig



Smsmanager Related introduction and use diagram:






Of course, in order to facilitate everyone, put the code sticky, you do not bother to write code:

Copy and paste it when you need it!

1) Call the system to send SMS functions:

public void Sendsmsto (String phonenumber,string message) {      //Determines whether the input phonenumber is a legitimate phone number    if ( Phonenumberutils.isglobalphonenumber (PhoneNumber)) {//uri.parse ("Smsto") here is converted to the specified Uri, fixed notation        Intent Intent = new Intent (Intent.action_sendto, Uri.parse ("Smsto:" +phonenumber));                    Intent.putextra ("Sms_body", message);                    StartActivity (intent);      }  }  



2) Call the system-provided SMS interface to send SMS:

public void Sendsms (String phonenumber,string message) {      //Get SMS Manager       Android.telephony.SmsManager Smsmanager = Android.telephony.SmsManager.getDefault ();      Split SMS content (SMS length limit), seemingly limited to 140 characters, that is,    //can only send 70 Chinese characters, more to split into a number of SMS send    //45th parameters, if there is no need to listen to send status and receive status can write null        list<string> dividecontents = smsmanager.dividemessage (message);       for (String text:dividecontents) {            smsmanager.sendtextmessage (phonenumber, NULL, text, SENTPI, deliverpi);        }  


Pendingintent to handle the sending status:

Processing the returned send status   String sent_sms_action = "Sent_sms_action";  Intent sentintent = new Intent (sent_sms_action);  Pendingintent SENTPI = pendingintent.getbroadcast (context, 0, sentintent,  0);  The broadcast recipient Context.registerreceiver (new Broadcastreceiver () {      @Override public      void OnReceive (Context _) that is registered to send the message Context, Intent _intent) {          switch (Getresultcode ()) {case          Activity.RESULT_OK:Toast.makeText (context, "SMS sent successfully ", Toast.length_short). Show ();  break;          Case Smsmanager.result_error_generic_failure:    //Common error break;        Case Smsmanager.result_error_radio_off:  //radio broadcast is explicitly closed for break;         Case SMSMANAGER.RESULT_ERROR_NULL_PDU:/          /not provided pdubreak;case Smsmanager.result_error_no_service:/         / The service is currently unavailable for break;}}  , New Intentfilter (sent_sms_action));  


Pendingintent to handle the receive state:

Handles the returned receive status   String delivered_sms_action = "Delivered_sms_action";  Create a Intent  Intent deliverintent = new Intent (delivered_sms_action) that receives the received status returned  ; Pendingintent Deliverpi = pendingintent.getbroadcast (context, 0,deliverintent, 0);  Context.registerreceiver (New Broadcastreceiver () {     @Override public     void OnReceive (Context _context, Intent _ Intent) {         Toast.maketext (context, "Recipient has successfully received", Toast.length_short). Show ();       






















--smsmanager of system services provided by Android (SMS manager)

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.