System services provided by Android-SmsManager)

Source: Internet
Author: User

System services provided by Android-SmsManager)

System services provided by Android-SmsManager)

-- Reprinted with the source: coder-pig



Introduction and illustration of SmsManager:





<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + PGJyPgo8L3A + signature + CjxwPjxzdHJvbmc + signature + Signature = "brush: java;"> public void SendSMSTo (String phoneNumber, String message) {// determine whether the entered phoneNumber is a valid phone number if (PhoneNumberUtils. isGlobalPhoneNumber (phoneNumber) {// Uri. parse ("smsto") Here is the conversion to the specified Uri, fixed syntax Intent intent = new Intent (Intent. ACTION_SENDTO, Uri. parse ("smsto:" + phoneNumber); intent. putExtra ("sms_body", message); startActivity (intent );}}


2) Call the SMS interface provided by the system to send text messages:

Public void sendSMS (String phoneNumber, String message) {// obtain the SMS manager android. telephony. smsManager smsManager = android. telephony. smsManager. getDefault (); // split the text message content (SMS length limit). It seems that the length is limited to 140 characters, that is, // only 70 Chinese characters can be sent, if you want to split the message into multiple SMS sending parameters, you can write a null List if you do not need to monitor the sending and receiving statuses.
 
  
DivideContents = smsManager. divideMessage (message); for (String text: divideContents) {smsManager. sendTextMessage (phoneNumber, null, text, sentPI, deliverPI );}}
 


PendingIntent that processes the sending status:

// Process the returned sending status String SENT_SMS_ACTION = "SENT_SMS_ACTION"; Intent sentIntent = new Intent (SENT_SMS_ACTION); PendingIntent sentPI = PendingIntent. getBroadcast (context, 0, sentIntent, 0); // register the broadcast receiver context. registerReceiver (new BroadcastReceiver () {@ Override public void onReceive (Context _ context, Intent _ intent) {switch (getResultCode () {case Activity. RESULT_ OK: Toast. makeText (context, "message sent successfully", Toast. LENGTH_SHORT ). show (); break; case SmsManager. RESULT_ERROR_GENERIC_FAILURE: // normal error break; case SmsManager. RESULT_ERROR_RADIO_OFF: // The break is explicitly disabled for wireless broadcasting; case SmsManager. RESULT_ERROR_NULL_PDU: // No pdubreak is provided; case SmsManager. RESULT_ERROR_NO_SERVICE: // break is currently unavailable for the service; }}, new IntentFilter (SENT_SMS_ACTION ));


PendingIntent processing the receipt status:

// Process the returned receipt status String response = "DELIVERED_SMS_ACTION"; // create the Intent deliverIntent = new Intent (DELIVERED_SMS_ACTION) that receives the returned receipt status; PendingIntent deliverPI = PendingIntent. getBroadcast (context, 0, deliverIntent, 0); context. registerReceiver (new BroadcastReceiver () {@ Override public void onReceive (Context _ context, Intent _ intent) {Toast. makeText (context, "the recipient has successfully received", Toast. LENGTH_SHORT ). show () ;}, new IntentFilter (DELIVERED_SMS_ACTION ));






















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.