0

I'm writing an android app where it forwards every notification on the device to GCM, which then subsequently sends to the registered chrome extension. Everything works fine except when my extension go offline for a while then back online, it will receive all messages queued up while extension was offline. This is not the behavior I want. I want to message to be discarded if the recipient is offline.

How can this be done?

Thanks

Leo Chen
  • 969
  • 1
  • 11
  • 25

1 Answers1

0

There is a parameter called time_to_live that you can set in while sending GCM to chrome extension. This accepts integer value which is seconds.

Time-to-live of the message in seconds. If it is not possible to send the message within that time, an onSendError event will be raised. A time-to-live of 0 indicates that the message should be sent immediately or fail if it's not possible. The maximum and a default value of time-to-live is 86400 seconds (1 day).

So while sending the GCM message to your chrome extension set this parameter to 0. What this will do is to discard the message when the extension is offline and won't sent it even when it is offline.

For additional details take a look at this chrome GCM official documentation.

AniV
  • 3,997
  • 1
  • 12
  • 17