This article describes the implementation of the Android SMS transmitter. Share to everyone for your reference. Specifically as follows:
Here to simulate the implementation of the Android SMS transmitter
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 the mobile 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> <t Extview 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 Smsmanager Manager=smsmanager.getdefault () in the Android system; If the message content is too long, then split the text message content arraylist<string> Texts=manager.dividemessage); for (String text:texts) {//The first parameter: the other cell phone number//second parameter: SMS Center number, general set to empty//third parameter: SMS content//Fourth parameter: Sentintent judge whether the message is sent successfully if you do not have SI
M card, or network interruption, can be judged by this intent. Note that the "Send" action is a success. So as to whether the other person received, another//fifth parameter: When the message sent to the recipient, you will receive this deliveryintent. That is, the emphasis on the "send" results//is said to be in the "message sent successfully" and "each other received this message" will activate Sentintent and deliveryintent these two intent.
This is also equivalent to delaying the execution of 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 Result:
I hope this article will help you with your Android program.