Create a new Android project.
A layout
Open the Main.xml to modify the contents as follows:
<textview android:layout_width= "fill_parent" android:layout_height= "wrap_content" android:text= "@string/number"/> <edittext android:layout_width= "fill_parent" android:layout_height= "Wrap_ Content " android:inputtype=" text " android:id=" @+id/number "/> <textview android:layout_ Width= "Fill_parent" android:layout_height= "wrap_content" android:text= "@string/content"/> <edittext android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android: Inputtype= "text" android:minlines= "3" android:id= "@+id/content"/> <button android: Layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "@string/button" Android:id= "@+id/button"/>
Two definition strings
Open Strings.xml Add content as follows:
<string name= "Number" > Please enter your mobile code </string><string name= "Content" > Please enter SMS content </string><string Name= "button" > Send SMS </string><string name= "Success" > Send success </string>
Three Response click events
Open Mainactivity.java and add the following code:
Public EditText numbertext;public EditText contenttext;public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); numbertext = (EditText) This.findviewbyid (R.id.number); ContentText = (EditText) This.findviewbyid (R.id.contenttext); Button button = (button) This.findviewbyid (R.id.button); Button.setonclicklistener (new Buttonclicklistener ());} Private Final class Buttonclicklistener implements view.onclicklistener{public void OnClick (View v) {String number = numb Ertext.gettext (). toString (); String content = Contenttext.gettext (). toString (); Smsmanager manger = Smsmanager.getdefault ();//Split text message words, if the extra 36 words sub-bar sent Arraylist<string> Texts=manger.dividemessa GE (content); for (String text:texts) {//parameter: number, center address, content, send status, whether the other party received status manger.sendtextmessage (numbers, NULL, text, NULL, NULL); }//SMS sent, notify the user Toast.maketext (Getapplicationcontext (), r.string.success, Toast.length_long). Show ();}}
Four Add permissions
To add permissions in Manifest.xml:
<uses-permission android:name= "Android.permission.SEND_SMS"/>
Android small feature to send SMS