Android path-second Android applet (Android SMS sending)

Source: Internet
Author: User

Continue to paste the code without saying anything:

The first is the layout code: Main. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <textview <br/> Android: TEXT = "@ string/inputmobile" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content"> <br/> </textview> <br/> <edittext <br/> Android: id = "@ + ID/mobile" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content"> <br/> </edittext> <br/> <textview <br/> Android: text = "@ string/inputmessage" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content"> <br/> </textview> <br/> <edittext <br/> Android: id = "@ + ID/message" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content"> <br/> </edittext> <br/> <button <br/> Android: text = "@ string/submit" <br/> Android: id = "@ + ID/submit" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content"> <br/> </button> <br/> </linearlayout> <br/> 

The following is the code of string. xml:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <resources> <br/> <string name = "app_name"> SMS sender </string> <br/> <string name = "inputmobile"> enter the mobile phone number: </string> <br/> <string name = "inputmessage"> enter the text message content: </string> <br/> <string name = "Submit"> send SMS </string> <br/> </resources> <br/> 

 

Both of the above are in res.

Next is the code messageactivity in SRC: (because it is in the company, there is no time to write comments, and so on)

 

Package CN. jason. android; <br/> Import Java. util. list; <br/> Import android. app. activity; <br/> Import android. app. pendingintent; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. telephony. GSM. smsmanager; <br/> Import android. view. view; <br/> Import android. widget. button; <br/> Import android. widget. edittext; <br/> Import android. widget. toast; <br/> public class messageactivity extends activity {<br/>/** called when the activity is first created. */<br/> @ override <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); </P> <p> final edittext returns enoedittext = (edittext) findviewbyid (R. id. mobile); <br/> final edittext messageedittext = (edittext) findviewbyid (R. id. message); <br/> button submitbutton = (button) findviewbyid (R. id. submit); </P> <p> submitbutton. setonclicklistener (new view. onclicklistener () {</P> <p> Public void onclick (view) {<br/> string moblilestring = mobilenoedittext. gettext (). tostring (); <br/> string messagestring = messageedittext. gettext (). tostring (); <br/> smsmanager = smsmanager. getdefault (); <br/> pendingintent sendingintent = pendingintent. getbroadcast (messageactivity. this, 0, new intent (), 0); <br/> List <string> msgslist = smsmanager. dividemessage (messagestring); <br/> for (string MSG: msgslist) {<br/> smsmanager. sendtextmessage (moblilestring, null, MSG, sendingintent, null); <br/>}< br/> toast. maketext (messageactivity. this, "sms sent successfully", toast. length_long ). show (); <br/>}< br/>}); </P> <p >}< br/>} 

You can't use the above statements. The most important sentence is as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "CN. jason. android "<br/> Android: versioncode =" 1 "<br/> Android: versionname =" 1.0 "> <br/> <application Android: icon = "@ drawable/icon" Android: Label = "@ string/app_name"> <br/> <activity Android: Name = ". messageactivity "<br/> Android: Label =" @ string/app_name "> <br/> <intent-filter> <br/> <action Android: Name =" android. intent. action. main "/> <br/> <category Android: Name =" android. intent. category. launcher "/> <br/> </intent-filter> <br/> </activity> <br/> </Application> <br/> <uses-SDK Android: minsdkversion = "4"/> <br/> <uses-Permission Android: Name = "android. permission. send_sms "/> <br/> </manifest> 

If the last sentence above does not exist, you cannot send text messages. This is the permission settings. Set the SMS sending permission. <Uses-Permission Android: Name = "android. Permission. 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.