Hi I have the following broadcast receiver so my activity is told when I receive an sms message. The only thing I haven't been able to figure out is how to get the id of the new sms. How can this be done? I know how to get the phone number and message but I don't need that I need it's id any help would be greatly appreciated
BroadcastReceiver sentSmsBroadcast = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == SMS_RECEIVED) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[])bundle.get("pdus");
final SmsMessage[] messages = new SmsMessage[pdus.length];
for (int i = 0; i < pdus.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
}
if (messages.length > -1) {
//Get sms id
}
}
}
}
};
IntentFilter filterSend = new IntentFilter();
filterSend.addAction("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sentSmsBroadcast, filterSend);
You are referring to the message ref id that is used to do dedup right? That field is in the SMSMessage however the api is not public. You will have to do some reflection to dig it out. Look in com.android.internal.telephony.SmsMessageBase
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With