Android small feature to send SMS

Source: Internet
Author: User
Tags gettext

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.