Question

when I broadcast pending intent and provide my data by putExtra() , I get these intents in receiver with same data and this equal the 1st created Pending intent . code :

for (int i = 0; i < parts.size(); i++) {
    mSendIntent=new  Intent("CTS_SMS_SEND_ACTION");
    mSendIntent.putExtra("key",i):
    sentIntents.add(PendingIntent.getBroadcast(smscontext, 0, mSendIntent,
            0));
}

I try to get my result with adding some flag to getBroadcast method but not successful ,any idea ?

Was it helpful?

Solution

To get a unique PendingIntent each time you call getBroadcast(), you need to provide either a unique Intent action or a unique request code. In your example it may be easiest to provide a unique request code. Try this:

for (int i = 0; i < parts.size(); i++) {
    mSendIntent=new Intent("CTS_SMS_SEND_ACTION");
    mSendIntent.putExtra("key", i):
    sentIntents.add(PendingIntent.getBroadcast(smscontext, i, mSendIntent, 0));
}

I've used i as the requestCode parameter. However, i may not be unique enough (I don't know the rest of your code). You may need to add the date or some other value to make it unique.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top