XML File Code section
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android" xmlns:tools= "Http://schemas.android.com/tools" android:layout_width= "Match_parent" android:layout_height= "Match_parent" android:padding= "10DP" ><edittext android:id= "@+id/phonenum" android: Layout_width= "Match_parent" android:layout_height= "Wrap_content" android:hint= "Please enter your mobile phone number" /><edittext android:id= "@+id/duanxin" android:layout_width= "Match_parent" android: layout_height= "200px" android:hint= "Please enter the SMS to be sent" android:layout_ below= "@id/phonenum" /><button android:id= "@+id/ Fasong " android:Layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:text= "Send" android:layout_below= "@id/duanxin" Android:layout_alignparentright= "true" /></RelativeLayout>
Public class mainactivity extends activity {private edittext phonenum, duanxin;private button button; @Override protected void oncreate (bundle savedinstancestate) { super.oncreate (savedinstancestate); setcontentview ( R.layout.activity_main); phonenum= (EditText) findViewById ( R.id.phonenum); duanxin= (EditText) Findviewbyid (R.id.duanxin); button= (Button) Findviewbyid (R.id.fasong); butlis lis=new butlis (); button.setonclicklistener (LIS); } class butlis implements onclicklistener{ @Override public void onclick (view v) { new thread (new runnable () {@ Overridepublic void run () {// TODO Auto-generated method stubString Num=phonenum.gettext (). toString (); smsmanager sms=smsmanager.getdefault (); sms.sendtextmessage (Num, null, duanxin.gettext (). toString (), null, null) ;}}). Start (); } }
This article is from the "Java White Battlefield" blog, be sure to keep this source http://8023java.blog.51cto.com/10117207/1663709
Android SMS send feature