Android sends SMS messages by calling the interface. android sends SMS messages
Android can send text messages in two ways
1. Call the system SMS interface to send the SMS directly. The main code is as follows:
Java code
- // Directly call the SMS interface to send text messages
- 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 function. The main code is as follows:
Java code
- 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 is from the Internet.:
1. Get the SMS Manager
Java code
- SmsManager smsManager = SmsManager. getDefault ();
2. Split the text message content (SMS length limit)
Java code
- List <String> divideContents = smsManager. divideMessage (content );
3. Send the split content
Java code
- List <String> divideContents = smsManager. divideMessage (content );
- For (String text: divideContents ){
- SmsManager. sendTextMessage ("150 xxxxxxxx", null, text, sentPI, deliverPI );
- }
4. process the returned sending status
Java code
- 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 ));
5. process the returned receiving status
Java code
- 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
Java code
- 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 ).
Call the SMS sending interface.
The answer is very detailed upstairs. I don't know whether you are asking about pc or mobile phone. If it is a pc end, you can contact Qida mobile in Beijing for technical support.
Android SMS interface, Introduction
Android SMS interface?
Not clear
You mean android Developers call the SMS sending interface.
Just like c, just find the webservice interface provided by the service provider, such as quickda mobile.