First, there are a few things to note:
1. Use of toast (toast)
Toast.maketext (This, "phone number and SMS content cannot be empty!") ", Toast.length_long). Show ();
2, SMS if more than send length remember to split
arraylist<string> Arrs = Sms.dividemessage (str_content);
3. The class for sending SMS: Smsmanager
4, remember to add users to send SMS permission: Android.permission.SEND_SMS
The key code is as follows:
public void OnClick (View arg0) {
TODO auto-generated Method Stub
Switch (Arg0.getid ())
{
Case R.id.btn_cancel:
This.edt_number.setText ("");
This.edt_content.setText ("");
Break
Case R.id.btn_send:
Valiad Empty
String str_num = Edt_number.gettext (). toString (). Trim ();
String str_content = Edt_content.gettext (). toString (). Trim ();
if ("". Equals (str_num) | | "". Equals (str_content))
{
Toast.maketext (This, "phone number and SMS content cannot be empty!") ", Toast.length_long). Show ();
Return
}
Smsmanager SMS = Smsmanager.getdefault ();
if (Str_content.length () >150)
{
arraylist<string> Arrs = Sms.dividemessage (str_content);
for (String Str:arrs)
{
Sms.sendtextmessage (Str_num, NULL, str_content, NULL, NULL);
}
}
Toast.maketext (This, "sent successfully! ", Toast.length_long). Show ();
Break
Default
Break
}
}
Android's lone formula: Message (SMS) to Lover