(Android Review) texting

Source: Internet
Author: User

1, Main.xml

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G    T <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:text= "mobile Number "/> <edittext android:id=" @+id/numet "android:layout_width=" Fill_parent "Android:layout_h        eight= "Wrap_content" android:inputtype= "Phone"/> <textview android:layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "SMS Content"/> <edittext android:id= "@+id/contentET "Android:layout_width=" fill_parent "android:layout_height=" wrap_content "android:inputtype=" TextMult ILine "android:lines=" 3 "/> <button android:layout_width=" Wrap_content "Android:layout_heigh t= "Wrap_content" Android:onclick= "Hello" android:text= "Send SMS"/></linearlayout> 


2, Mainactivity

Package Com.example.smstest;import Java.util.list;import Android.os.bundle;import android.app.activity;import Android.telephony.smsmanager;import Android.view.menu;import Android.view.view;import Android.widget.EditText; Import Android.widget.toast;public class Mainactivity extends Activity {private EditText et_num;private EditText et_ Content; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.main); et_num = (EditText) Findviewbyid (r.id.numet); et_content = (EditText) Findviewbyid ( R.id.contentet);} public void Hello (view view) {String num = Et_num.gettext (). toString (); String content = Et_content.gettext (). toString ();/** * Below is the core code for texting */smsmanager Smsmanager = Smsmanager.getdefault (); list<string> list = smsmanager.dividemessage (content);//split SMS content. For handling a message that is too long ... for (String str:list) { Smsmanager.sendtextmessage (num, null, str, NULL, NULL);} Toast.maketext (This, "Hello SMS", 1). Show (); @Overridepublic Boolean oncreateoptIonsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is present.getmenuinflater (). Inflate (r.m Enu.main, menu); return true;}}



3, Androidmanifest.xml

<uses-permission android:name= "Android.permission.SEND_SMS"/>



SOURCE Download: http://download.csdn.net/detail/caihongshijie6/7600765




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.