In android, you can call interfaces to send text messages in two ways.

Source: Internet
Author: User

First, call the system SMS interface to send text messages directly.The main code is as follows:

Copy codeThe Code is as follows: // directly call the SMS interface to send a text message
SmsManager smsManager = SmsManager. getDefault ();
List <String> divideContents = smsManager. divideMessage (content );
For (String text: divideContents ){
SmsManager. sendTextMessage ("150 xxxxxxxx", null, text, sentPI, deliverPI );
}

Second: Call the system's text message functionThe main code is as follows:Copy codeThe Code is as follows: Uri uri = Uri. parse ("smsto: 10010 ");
Intent it = new Intent (Intent. ACTION_SENDTO, uri );
It. putExtra ("sms_body", "102 ");
Activity. startActivity (it );

The first method is described here. Most of the information comes from the Internet:
Get SMS Manager
Copy codeThe Code is as follows: SmsManager smsManager = SmsManager. getDefault ();

Split text message content (SMS length limit)Copy codeThe Code is as follows: List <String> divideContents = smsManager. divideMessage (content );

Sent split contentCopy codeThe Code is as follows: List <String> divideContents = smsManager. divideMessage (content );
For (String text: divideContents ){
SmsManager. sendTextMessage ("150 xxxxxxxx", null, text, sentPI, deliverPI );
}

Processing returned sending statusCopy codeThe Code is as follows: 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 Receivers
Context. registerReceiver (new BroadcastReceiver (){
@ Override
Public void onReceive (Context _ 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:
Break;
Case SmsManager. RESULT_ERROR_RADIO_OFF:
Break;
Case SmsManager. RESULT_ERROR_NULL_PDU:
Break;
}
}
}, New IntentFilter (SENT_SMS_ACTION ));

Processing the returned receiving statusCopy codeThe Code is as follows: String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION ";
// Create the deilverIntent parameter
Intent deliverIntent = new Intent (DELIVERED_SMS_ACTION );
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 the message", Toast. LENGTH_SHORT)
. Show ();
}
}, New IntentFilter (DELIVERED_SMS_ACTION ));

Description of parameters for sending SMS messages Copy codeThe Code is as follows: smsManager. sendTextMessage (destinationAddress, scAddress, text, sentIntent, deliveryIntent)

-- DestinationAddress: the destination phone number.
-- ScAddress: the number of the SMS center. This parameter can be left empty for testing.
-- Text: text message content
-- SentIntent: Send --> China Mobile failed to send --> return the sending success or failure signal --> after processing, this intent encapsulates the message sending status.
-- DeliveryIntent: Send --> China Mobile sends the message successfully --> Returns whether the recipient receives the message --> subsequent processing: this intent encapsulates the status information of the message received by the other party (the supplier has successfully sent the message but the other party has not received it ).

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.