Android's lone formula: Message (SMS) to Lover

Source: Internet
Author: User

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

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.