Learning note 7-android SMS transmitter

Source: Internet
Author: User
Tags gettext

Create a new Android project SNS.

Add text to String.xml

< Resources >

< string name="app_name">Sns send sms </string>

< string name="Hello">Hello World, mainactivity! </ string >

< string name="number"> Enter mobile phone </string>

< string name="Content"> Please enter SMS content </string>

< string name="button"> send </string>

< string name="Success"> send complete </string>

</ Resources >

Setting the interface 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/number"/>

< EditText

android:layout_width="Fill_parent"

android:layout_height="Wrap_content"

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: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"/>

</ LinearLayout >

Set Button click events

Public class Mainactivity extends Activity {

Private EditTextNumbertext;

Private EditTextContentText;

@Override

Public void onCreate (bundlesavedinstancestate) {

Super. onCreate (savedinstancestate);

Setcontentview (r.layout. Main);

numbertext = (EditText)this. Findviewbyid (r.id. number);

ContentText = (EditText)this. Findviewbyid (r.id. Content);

Button button = (Button) this. Findviewbyid (r.id. button);

Button.setonclicklistener (new Buttonclcklistener ());

}

Private final class Buttonclcklistenerimplements view.onclicklistener{

Public void OnClick (View v) {

String number = numbertext. GetText (). toString ();

String content = contenttext. GetText (). toString ();

Smsmanager Manager =smsmanager. Getdefault ();

Arraylist<string> texts =manager.dividemessage (content);

for (String text:texts) {

// The latter two parameters sentintent, Deliveryintent (send status, whether to receive SMS status

Manager.sendtextmessage (number, null, text,null, null);

}

Toast. Maketext (Mainactivity. this, r.string. success, Toast. Length_long). Show ();

}

}

}

Three notifications of successful delivery

1. Status bar Notification

2. dialog box notification

3. Spit (Toast) (Eject sent successfully, one second automatically disappears)

Set permissions

Send SMS to set permissions, we are in the SDK at docs→index.html

Here you can see all the permissions search send SMS can see the right to send text messages

can find

You can then request permissions in manifest (under the Manifest node)

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

Install the application test

Send a text message to another simulator.

Send a successful toast effect


Learning note 7-android SMS transmitter

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.