1, Main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G T <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:text= "mobile Number "/> <edittext android:id=" @+id/numet "android:layout_width=" Fill_parent "Android:layout_h eight= "Wrap_content" android:inputtype= "Phone"/> <textview android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "SMS Content"/> <edittext android:id= "@+id/contentET "Android:layout_width=" fill_parent "android:layout_height=" wrap_content "android:inputtype=" TextMult ILine "android:lines=" 3 "/> <button android:layout_width=" Wrap_content "Android:layout_heigh t= "Wrap_content" Android:onclick= "Hello" android:text= "Send SMS"/></linearlayout>
2, Mainactivity
Package Com.example.smstest;import Java.util.list;import Android.os.bundle;import android.app.activity;import Android.telephony.smsmanager;import Android.view.menu;import Android.view.view;import Android.widget.EditText; Import Android.widget.toast;public class Mainactivity extends Activity {private EditText et_num;private EditText et_ Content; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); et_num = (EditText) Findviewbyid (r.id.numet); et_content = (EditText) Findviewbyid ( R.id.contentet);} public void Hello (view view) {String num = Et_num.gettext (). toString (); String content = Et_content.gettext (). toString ();/** * Below is the core code for texting */smsmanager Smsmanager = Smsmanager.getdefault (); list<string> list = smsmanager.dividemessage (content);//split SMS content. For handling a message that is too long ... for (String str:list) { Smsmanager.sendtextmessage (num, null, str, NULL, NULL);} Toast.maketext (This, "Hello SMS", 1). Show (); @Overridepublic Boolean oncreateoptIonsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (r.m Enu.main, menu); return true;}}
3, Androidmanifest.xml
<uses-permission android:name= "Android.permission.SEND_SMS"/>
SOURCE Download: http://download.csdn.net/detail/caihongshijie6/7600765