Android self-learning notes-6-simple text message sender

Source: Internet
Author: User

The simple text message sender has the following effects:

The java code is as follows:

Package com. mxy. smssend; import java. util. arrayList; import android. app. activity; import android. OS. bundle; import android. telephony. smsManager; import android. text. textUtils; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. editText; import android. widget. toast;/*** you need to add the SMS sending permission * @ author Administrator **/public class MainActivity extends Activity implements OnClickListener {private EditText mEditTextNumber; private EditText mEditTextContent; private Button mButtonSmsSend; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // load the layout file setContentView (R. layout. activity_main); // obtain the mEditTextNumber = (EditText) findViewById (R. id. et_number); mEditTextContent = (EditText) findViewById (R. id. et_content); mButtonSmsSend = (Button) findViewById (R. id. btn_smssend); // bind to the button and click the event mButtonSmsSend. setOnClickListener (this) ;}@ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. btn_smssend: // obtain the phone number and content String number = mEditTextNumber. getText (). toString (). trim (); String content = mEditTextContent. getText (). toString (). trim (); // check whether the phone number is empty if (TextUtils. isEmpty (number) {Toast. makeText (this, "Enter your mobile phone number", Toast. LENGTH_LONG ). show ();} else {// if the content is too long, it needs to be split into multiple sending messages. if the content is not split, SmsManager smsManager = SmsManager cannot be sent successfully. getDefault (); ArrayList
 
  
Contents = smsManager. divideMessage (content); for (String str: contents) {// parameter the content of the sender's number of the receiver's number returned when the message is sent successfully or fails when the message is sent to the receiver. sendTextMessage (number, null, str, null, null) ;}} break ;}}}
 
Project download link: http://pan.baidu.com/s/1kTiFgaz

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.