Second, SMS transmitter

Source: Internet
Author: User

Simulation of Android SMS transmitter implementation

Androidmanifest.xml manifest file

<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.ljq.sms"
Android:versioncode= "1"
Android:versionname= "1.0" >
<application android:icon= "@drawable/icon" android:label= "@string/app_name" >
<activity android:name= ". Mainactivity "
Android:label= "@string/app_name" >
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

</application>
<USES-SDK android:minsdkversion= "7"/>
<uses-permission android:name= "Android.permission.SEND_SMS"/>

Main.xml Layout file

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<relativelayout android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content" >
<textview android:layout_width= "115dip"
android:layout_height= "Wrap_content"
android:text= "Please enter your phone number"
Android:id= "@+id/mobilelabel"/>
<edittext android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:layout_torightof= "@id/mobilelabel"
android:text= "5556"
Android:id= "@+id/mobile"/>
</RelativeLayout>
<textview android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "Please enter SMS Content"/>
<edittext android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:minlines= "3"
android:text= "I am a teacher!"
Android:id= "@+id/content"/>
<button android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "Send"
Android:id= "@+id/button"/>
</LinearLayout>

Mainactivity class

Package com.ljq.sms;

Import java.util.ArrayList;

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;

public class Mainactivity extends Activity {
Private EditText Mobiletext=null;
Private EditText Contenttext=null;

@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);

mobiletext= (EditText) Findviewbyid (r.id.mobile);
contenttext= (EditText) Findviewbyid (r.id.content);
Button button= (button) Findviewbyid (R.id.button);
Button.setonclicklistener (New View.onclicklistener () {

public void OnClick (View v) {
String Mobile=mobiletext.gettext (). toString ();
String Content=contenttext.gettext (). toString ();

Get the default SMS manager in Android system
Smsmanager Manager=smsmanager.getdefault ();
If the text message content is too long, then the content of the text is split
Arraylist<string> texts=manager.dividemessage (content);
for (String text:texts) {
First parameter: Phone number of the other person
Second parameter: SMS center number, generally set to empty
Third parameter: SMS content
The fourth parameter: Sentintent determine whether the text message is sent successfully, if you do not have a SIM card, or network interruption, you can use this intent to judge.
Note the emphasis is on whether the "send" action was successful. So as for whether or not the other party received
Fifth parameter: When a text message is sent to the recipient, it receives the deliveryintent. The result of "send" is emphasized.
This means that the two intent of sentintent and deliveryintent are activated when the message is sent successfully and the recipient receives this message. This is also equivalent to delaying the execution of the intent
Manager.sendtextmessage (mobile, NULL, text, NULL, NULL);
}
Toast.maketext (Getapplicationcontext (), "Send Success", Toast.length_long). Show ();
Toast.maketext (Mainactivity.this, "Send Success", Toast.length_long). Show ();
}
});
}
}

Run results

Second, 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.