Get message flow id or _id from onReceive android

I tried to get the message id that is stored on the phone. But I did not succeed. My existing code is here

@Override public void onReceive(Context context, Intent intent) { String address = ""; String message = ""; String msg_id=""; Bundle extras = intent.getExtras(); if (extras != null) { Object[] smsExtra = (Object[]) extras.get("pdus"); for (int i = 0; i < smsExtra.length; i++) { SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]); message += sms.getMessageBody(); address = sms.getOriginatingAddress(); } sms = new Sms(msg_id,message, address); UploadSms up = new UploadSms(); up.start(); Toast.makeText(context, "SMS Received>>" + message + "From >>" + address, Toast.LENGTH_LONG).show(); } } 

Under this, I get the sms body and sender number. But I know that for each message in the Android phone there is a unique number, I extracted it. But it was not possible to receive in methods onReceive. Thanks

+7
source share
1 answer

You will have to parse the SMS PDU (in raw PDU format), since there is no API at the Android application level to retrieve the user data header. I believe the short message identifier is in the header of user data (octet 1). See Message Parse SMS PDU .

In this message, one user mentions a freeware called "SMSLib" (licensed under the APACHE license) for analyzing and retrieving message parameters. The message identifier can be retrieved using the getMessageId () - Method method in the org.smslib.Message class.

Hope this helps.

0
source

All Articles