Package Com.example.sendsms;import Java.util.arraylist;import Android. R.array;import android.net.uri;import android.os.bundle;import Android.app.activity;import android.content.Intent; Import Android.telephony.smsmanager;import Android.view.menu;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;public Class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main); final EditText txtnum = (EditText) This.findviewbyid ( R.id.txtnumber); final EditText txtbody = (EditText) This.findviewbyid (r.id.txtbody); Button btnsms = (button) This.findviewbyid (r.id.btnsend); Btnsms.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View arg0) {//TODO auto-generated method stubstring num = Txtnum.gettext (). toString (); String BODY = Txtbody.gettext (). toString (); Smsmanager manager = Smsmanager.getdefault (); Arraylist<string> list = Manager.dividemessage (body); for (String text:list) {manager.sendtextmessage (num, NULL, Body, NULL, NULL);}}); Button Btncall = (button) This.findviewbyid (R.id.btncall); Btncall.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View arg0) {//TODO auto-generated method stubstring num = Txtnum.gettext (). toString (); Intent Intent = new Intent (Intent.action_call,uri.parse ("Tel:" +num);//tel: It is necessary to do so startactivity (intent);});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
(1) Smsmanager manager = Smsmanager.getdefault (); Get the default message manager
(2) arraylist<string> list = manager.dividemessage (String txt); Split Long text messages
(3) manager.sendtextmessage (String phone,null,string content,null,null); Send SMS
Add to Permissions
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Getting Started with Android: texting and making calls