Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCM collapse_key not working

I have a python/django app that is sending push notifications to GCM and I can't get the collapse_key parameter to work. It creates a new notification for each new message instead of collapsing them. The python code looks like this:

  url = 'https://gcm-http.googleapis.com/gcm/send'                                                                                        
  post_data = {                                                                   
      'to': mytoken,                                                                
      'collapse_key': 'myappname',                                                  
      'data': mydata                                                                
  }                                                                               
  headers = {                                                                     
      'Authorization': 'key={}'.format(GCM_API_KEY),                     
      'Content-Type': 'application/json'                                          
  }                                                                                                                                               
  requests.post(                                                                  
      url,                                                                        
      data=json.dumps(post_data),                                                 
      headers=headers) 

The notifications go through no problem but they don't collapse. Am I doing something wrong?

The client side is a phonegap mobile app using the phonegap push notifications plugin (https://github.com/phonegap-build/PushPlugin). The plugin is handling the push notifications on the device, i'm not sure how to change the way it creates and displays them.

If anyone else is having the same issue it looks like the way to do it is to pass the notId parameter in data. Notifications with the same notId will replace each other.

like image 334
sean2000 Avatar asked Oct 17 '25 10:10

sean2000


1 Answers

collapse_key only has an effect when the device is offline, for example if my device is in aeroplane mode, and it gets sent 5 messages with the same collapse_key, the device would only get the last one when aeroplane mode is turned off.

If a device is continuously connected to GCM, then each message will arrive on your device.

It sounds like you want to set a tag on your notification, so that when a new message arrives it will replace the existing notification.

like image 122
morepork Avatar answered Oct 19 '25 00:10

morepork



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!