<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "com. ISS. test "<br/> Android: versioncode =" 1 "<br/> Android: versionname =" 1.0 "> <br/> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name"> <br/> <activity Android: Name = ". testsmsactivity "<br/> Android: Label =" @ string/app_name "> <br/> <intent-filter> <br/> <action Android: Name =" android. inten T. action. main "/> <br/> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> </P> <p> </Application> </P> <p> <! -- Add permission --> <br/> <uses-Permission Android: Name = "android. Permission. send_sms"/> </P> <p> </manifest>
Package COM. ISS. test; </P> <p> Import android. app. activity; <br/> Import android. app. pendingintent; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. telephony. smsmanager; <br/> Import android. util. log; <br/> Import android. view. view; <br/> Import android. view. view. onclicklistener; <br/> Import android. widget. button; <br/> Import android. widget. edittext; <br/> Import android. widget. toast; </P> <p> public class testsmsactivity extends activity implements onclicklistener <br/>{</P> <p> Private Static final string tag = "testsmsactivity "; </P> <p> private edittext num; <br/> private edittext text; <br/> private button buttonsend; </P> <p>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) <br/>{< br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> initview (); <br/>}</P> <p> private void initview () <br/>{< br/> num = (edittext) findviewbyid (R. id. edittext01); <br/> text = (edittext) findviewbyid (R. id. edittext02); <br/> buttonsend = (button) findviewbyid (R. id. button01); <br/> buttonsend. setonclicklistener (this); </P> <p >}</P> <p> @ override <br/> Public void onclick (view V) <br/> {<br/> switch (v. GETID () <br/>{< br/> case R. id. button01: <br/> string strnum = num. gettext (). tostring (); <br/> string strcontent = text. gettext (). tostring (); <br/> smsmanager = smsmanager. getdefault (); <br/> pendingintent sentintent = pendingintent. getbroadcast (testsmsactivity. this, 0, new intent (), pendingintent. flag_one_shot); <br/> log. E (TAG, "strnum" + strnum + "strcontent" + strcontent); <br/> smsmanager. sendtextmessage (strnum, null, strcontent, null, null); <br/> toast. maketext (testsmsactivity. this, "message sent successfully", toast. length_long ). show (); <br/> break; <br/> default: <br/> break; <br/>}</P> <p >}< br/>