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