Android sends SMS messages

Source: Internet
Author: User

 Android sends SMS messages

 

Layout layout file 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" >    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/mobile" />    <EditText        android:id="@+id/mobile"        android:layout_width="fill_parent"        android:layout_height="wrap_content" />    <TextView        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/content" />    <EditText        android:id="@+id/content"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:minLines="3" />    <Button        android:id="@+id/button"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/button" /></LinearLayout>

 

 

Strings. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "hello"> Hello smsactivity! </String> <string name = "app_name"> text message sender </string> <string name = "mobile"> enter the mobile phone number </string> <string name = "content"> enter the text message content </string> <string name = "button"> send SMS </string> <string name = "success"> message sent successfully </string> </ resources>

 

Androidmanifest. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: Android = "http://schemas.android.com/apk/res/android" package = "com. cloud. android. SMS "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <uses-SDK Android: minsdkversion =" 7 "/> <! -- The program adds the SMS sending permission --> <uses-Permission Android: Name = "android. permission. send_sms "/> <application Android: icon =" @ drawable/agree_logo "Android: Label =" @ string/app_name "> <activity Android: label = "@ string/app_name" Android: Name = ". sms_cloudactivity "> <intent-filter> <action Android: Name =" android. intent. action. main "/> <category Android: Name =" android. intent. category. launcher "/> </intent-filter> </activity> </Application> </manifest>

 

Sms_cloudactivity.java

Package COM. cloud. android. SMS; import Java. util. list; import android. app. activity; import android. OS. bundle; import android. telephony. smsmanager; import android. view. view; import android. widget. button; import android. widget. edittext; import android. widget. toast;/*** text message sender (manual) * @ author Li haiyun * @ email CloudComputing.cc@gmail.com * @ date 2012-02-26 00:06:22 */public class sms_cloudactivity extends activity {@ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); button = (button) This. findviewbyid (R. id. button); button. setonclicklistener (new view. onclicklistener () {@ override public void onclick (view v) {// get the mobile phone number and content edittext mobiletext = (edittext) findviewbyid (R. id. mobile); edittext contenttext = (edittext) findviewbyid (R. id. content); string mobile = mobiletext. gettext (). tostring (); string content = contenttext. gettext (). tostring (); // send SMS smsmanager = smsmanager. getdefault (); List <string> texts = smsmanager. dividemessage (content); // if the number of Chinese characters exceeds the limit, the system automatically splits the message for (string text: texts) {smsmanager. sendtextmessage (mobile, null, text, null, null);} // toast notification with toast. maketext (sms_cloudactivity.this, R. string. success, toast. length_long ). show ();}});}}

 

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.