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