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 ));