Text message sending in Android case

Source: Internet
Author: User
In fact, the steps for sending text messages are the same as those for calling. Step 1: Page 1, Res/layout/main. XML file <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/user"/> <edittext Android: id = "@ + ID/user" Android: layout_width = "match_parent" Android: layout_height = "50dp"/> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/content"/> <edittext Android: Id = "@ + ID/content" Android: layout_width = "match_parent" Android: layout_height = "50dp"/> <button Android: Id = "@ + ID/Send" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "@ string/Send"/> 2. Res/values/strings. XML <string name = "app_name"> SMS sending interface </string> <! -- Step 1: write the corresponding text content --> <string name = "user"> receiver </string> <string name = "content"> information content </string> <string name = "Send "> send </string> Step 2: note that the intention of sending a text message is different from that of calling sendmessageactivity. javapublic class sendmessageactivity extends activity implements onclicklistener {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // obtain the component button sendbtn = (button) findviewbyid (R. id. send); // register the event sendbtn. setonclicklistener (this) ;}@ suppresswarnings ("deprecation") @ overridepublic void onclick (view v) {// todo auto-generated method stubedittext user = (edittext) findviewbyid (R. id. user); edittext content = (edittext) findviewbyid (R. id. content); // information management object smsmanager = smsmanager. getdefault (); // The normal intent state of the Request Code represented by the last three parameters: pendingintent intent = pendingintent. getbroadcast (sendmessageactivity. this, 0, new intent (), 0); // send smsmanager information. sendtextmessage (user. gettext (). tostring (), null, content. gettext (). tostring (), intent, null); // The message is successfully sent toast. maketext (sendmessageactivity. this, "message sent successfully", toast. length_long ). show () ;}} Step 3: Add a user permission similar to the call procedure, except that the permission is 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.