I am trying to send SMS messages from an Android application. I use PendingIntent, so I can use the broadcast receiver to check if it was sent normally. Since the sendTextMessage call will be made for each SMS message, I need to send some โadditionalโ data to determine the actual SMS message, since my broadcast reception can do some work on a specific SMS message.
Here is my send code:
String SENT = "SMS_SENT"; Intent sentIntent = new Intent(SENT); sentIntent.putExtra("foo", "BAR"); PendingIntent sentPI = PendingIntent.getBroadcast(baseContext, 0, sentIntent, 0); PendingIntent deliveredPI = PendingIntent.getBroadcast(baseContext, 0, new Intent(DELIVERED), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(smsMessage.getNumber(), null, smsMessage.getText(), sentPI, deliveredPI);
The problem is that in my BroadCast receiver it cannot read my extra "foo":
public class SMSSentBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context arg0, Intent intent) { String smsID = intent.getStringExtra("foo"); ...... } }
smsID just becomes null.
My broadcast receiver is registered as follows:
baseContext.registerReceiver(new SMSSentBroadcastReceiver(), new IntentFilter("SMS_SENT"));
Given that the intent filter works, what am I doing wrong? Why are additional services also not sent?
Any help is appreciated. Thanks
android android-intent android-service
jtnire
source share