1

A couple months ago, we implemented the direct reply functionality for Android 7, so users can reply to chatmessages via the received pushnotification. To accomplish this, we leveraged the support-library and used RemoteInput, but found a massive bug.

When a user receives pushnotifications for 2 different chats and replies to the one he received first, the message would be sent to the user of the later message. Even if you got multiple messages, the same issue would persist.

this is the specific code used link

Did I make a mistake with my implementation or is this a platform bug?

AL.
  • 33,241
  • 9
  • 119
  • 257
  • Hi @TormundThunderfist. It would be better if you copy-paste the code in your post so that the community would be able to see the code immediately. Plus, if ever the link goes down, its already safe and visible here. Cheers! – AL. Jul 16 '18 at 10:07
  • Don't know, but have found in the past that most PendingIntent/Broadcast caching issues can be solved either by 1. Adding a unique request code in getBroadcast instead of 100 in the sample 2. Or adding a unique field to the PendingIntent such as 'time' = System.currentTimeMillis() – Elletlar Jul 16 '18 at 11:57
  • @Elletlar your solution with the request code ended up being the most accessible solution. Please post your solution as a proper answer, so I can flag it accordingly – TormundThunderfist Jul 16 '18 at 13:57
  • Great. Happy to hear that it is working. :) :) :) Solution Posted. Cheers. – Elletlar Jul 16 '18 at 14:10

1 Answers1

1

The solution is to set a unique request code to preserve the pending intent:

public static PendingIntent getBroadcast (Context context, 
    int requestCode, 
    Intent intent, 
    int flags)

From the docs:

int: Private request code for the sender

More detailed info: What is a request code used for

Elletlar
  • 2,819
  • 7
  • 27
  • 33