In the messaging program I made, I used pending intent to receive the message sending and delivery report. When I send several messages and wait for the delivery report, the program does not recognize which message the received pending intent belongs to.
My code is:
sentSMS = PendingIntent.getBroadcast(this, msgId(), new Intent(SMS_SENT), 0); deliverSMS = PendingIntent.getBroadcast(this, msgId(), new Intent(SMS_DELIVERED), 0);
According to what I searched for, I have to use the request code parameter for this, for each message I have assigned a request code **(the ID of each message from the database) **in pending intent, but I don't know how to receive it in on receive.
thanks
Also i tried this:
Intent deliveryIntent = new Intent();
deliveryIntent.putExtra("id", msgId());
deliverSMS = PendingIntent.getBroadcast(this, msgId(), deliveryIntent, 0);
//************
Intent sendIntent = new Intent();
sendIntent.putExtra("id", msgId ());
sentSMS = PendingIntent.getBroadcast(this, msgId(), sendIntent, 0);
But I did not receive anything in extra
TThanks
When you create the
PendingIntent, you need to specifyPendingIntent.UPDATE_CURRENTas the last parameter of thegetBroadcast()call. This will ensure that eachPendingIntenthas the correct "id".In
onReceive()you should get the broadcastIntentand it should contain the "extra" named "id" with the message ID.However, if you create the
Intentwithout an ACTION and without a component or package name, youronReceive()will never get called. Please edit your question and show how you have set up yourBroadcastReceiver.