package com.android.myBroadcastTest;
import java.util.ArrayList;
import java.util.Iterator;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.util.Log;
public class myBroadcastTest extends BroadcastReceiver {
private final String MSG_LOG = "REC_LOG";
@Override
public void onReceive(Context context, Intent intent) {
ArrayList<String> divideMsg = null;
Log.d(MSG_LOG, "onReceive");
Bundle bundle = intent.getExtras();
if(bundle != null)
{
String strPhone = bundle.get("PhoneNumber").toString();
String strMsg = bundle.get("SMSMessage").toString();
Log.d(MSG_LOG, strPhone);
Log.d(MSG_LOG, strMsg);
SmsManager smsManager = SmsManager.getDefault();
PendingIntent mPI = PendingIntent.getBroadcast(context, 0, new Intent(), 0);
//smsManager.sendTextMessage(strPhone, null, strMsg, mPI, null);
divideMsg = smsManager.divideMessage(strMsg);
Iterator<String> iterator = divideMsg.iterator();
while(iterator.hasNext()){
String strTmp = iterator.next();
smsManager.sendTextMessage(strPhone, null, strTmp, mPI, null);
}
}
abortBroadcast();
}
}
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.myBroadcastTest" android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<receiver
android:name=".myBroadcastTest">
<intent-filter>
<action android:name="mySendSMS" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
</manifest>
use adb command
adb shell am broadcast -a mySendSMS --es "0123455667" --es "SMS message send test"