First: Call the system SMS interface to send SMS directly ; The main code is as follows:
Copy Code code as follows:
Directly call SMS interface to send text messages
Smsmanager Smsmanager = Smsmanager.getdefault ();
list<string> dividecontents = smsmanager.dividemessage (content);
for (String text:dividecontents) {
Smsmanager.sendtextmessage ("150xxxxxxxx", null, Text, SENTPI, DELIVERPI);
}
Second: The system to send SMS function; The main code is as follows:
Copy Code code as follows:
Uri uri = uri.parse ("smsto:10010");
Intent it = new Intent (intent.action_sendto, URI);
It.putextra ("Sms_body", "102");
Activity.startactivity (IT);
This is mainly about the first method, most of which comes from the Internet:
Get Message Manager
Copy Code code as follows:
Smsmanager Smsmanager = Smsmanager.getdefault ();
Split SMS content (SMS length limit)
Copy Code code as follows:
list<string> dividecontents = smsmanager.dividemessage (content);
Send the split content
Copy Code code as follows:
list<string> dividecontents = smsmanager.dividemessage (content);
for (String text:dividecontents) {
Smsmanager.sendtextmessage ("150xxxxxxxx", null, Text, SENTPI, DELIVERPI);
}
Handling the Send status returned
Copy Code code 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 Send Success", 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 received status returned
Copy Code code 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,
"Recipient has successfully received", Toast.length_short)
. Show ();
}
}, New Intentfilter (delivered_sms_action));
parameter description of sending SMS
Copy Code code as follows:
Smsmanager.sendtextmessage (destinationaddress, scaddress, text, sentintent, deliveryintent)
--destinationaddress: Target phone number
--scaddress: SMS Center number, test can not fill
--Text: SMS Content
--sentintent: Send--> China Mobile--> send failure--> return send success or failure signal--> subsequent processing that is, this intent to package the message sent status information
--deliveryintent: Send--> China Mobile--> to send a successful--> back to the other side whether received this information--> follow-up processing that is: this intention to wrap the message is received by the other side of the status information (the supplier has been sent successfully, But the other side did not receive it.