Ghouse Ghouse - 1 year ago 129
Android Question

Send sms pending intent extras get overide

Hi I'm sending messsage from my app through SmsManager in my service and register broadcast receivers for sms sent and delivered where I want to update message status as it is reached or not. As per now I'm able to send messages by putting extras with row id in Pending Intent with flag

. But once messages is send I'm receiving broadcast events with extras of last row only and I'm not able to retrieve extras of other rows. I'm using PendingIntent.FLAG_UPDATE_CURRENT that is why extras are getting override and I have checked other flags also but of no use. How to get extras of other rows also without being override? and one more thing I am sending sms in service is this approach proper? Any suggestions will be

of great help.

String mSelectionClause = MyContentprovider.STATUS+ " = ?";
String[] mSelectionArgs = {"fail"};

Uri students = MyContentprovider.CONTENT_URI_SENDMSG;
Cursor c = getContentResolver().query(students, null, mSelectionClause, mSelectionArgs, "userphno");
if (c.moveToFirst()) {

String SENT = "SMS_SENT";

Intent SENTINTENT=new Intent(SENT);
SENTINTENT.putExtra("id",c.getString(c.getColumnIndex( MyContentprovider._ID)));
SENTINTENT.putExtra("userno", c.getString(c.getColumnIndex( MyContentprovider.USER_PHNO)));

SENTINTENT.putExtra("lastrow", "true");


DELIVEREDINTENT.putExtra("id",c.getString(c.getColumnIndex( MyContentprovider._ID)));
DELIVEREDINTENT.putExtra("userno", c.getString(c.getColumnIndex( MyContentprovider.USER_PHNO)));

PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,

PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,

String msg= c.getString(c.getColumnIndex( MyContentprovider.MESSAGE));

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage( c.getString(c.getColumnIndex( MyContentprovider.USER_PHNO)), null, msg, sentPI, deliveredPI);

and in broadcast receiver and I am storing the ids of row nothing much code there

Answer Source

The solution I found is to pass a unique int for the requestCode (the second argument) in:

PendingIntent.getBroadcast(this, 0, SENTINTENT, PendingIntent.FLAG_UPDATE_CURRENT)

Then it creates a new PendingIntent for each.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download