Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get SMS ID from broadcast receiver

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);
like image 498
user577732 Avatar asked Jun 13 '13 20:06

user577732


1 Answers

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

like image 176
Phuong Nguyen Avatar answered Sep 21 '22 09:09

Phuong Nguyen