Reputation: 4056
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);
Upvotes: 8
Views: 2727
Reputation: 18
messages[0].getIndexOnIcc()
should provide the index based off of the entity declaration under com.android.internal.telephony.SmsMessageBase
Upvotes: 0
Reputation: 909
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
Upvotes: 2