Search code examples
androidwifipushandroid-c2dm

How do I get C2DM push notifications to work together with WiFi enabled?


I've done an app which uses C2DM pusn notifications. Everything works fine as long as I am connected to the GSM/3G network but when I switch to WiFi it does not always work and I do not receive push notifications.

I understand the technical problems when it comes to WiFi and push (firewalls et c).

My question is if there's any smart solutions for this (Yes I know I could switch to "polling" in my app). Is it possible to use GSM/3G and WiFi at the same time, or is Android already doing this when connecting to WiFi?

/ Henrik


Solution

  • I've worked with C2DM quite a lot this year, and I have seen the issue you are describing. I have also heard it happens with iOS devices. I sometimes find push fails and putting the device into Airplane mode and back out again re-enables push message reception.

    But anyway in our case the solution was two-fold:

    1. Replace the device with one that could maintain a push message connection across wifi. In our case we had a test device that was particularly prone to the problem.

    2. Build a polling mechanism as a (slow) backup for C2DM. This obviously means more effort, more code, more battery & data usage, but in our case the resulting app is very reliable as a result, even with some problems with C2DM.

    My experience is that C2DM is great generally and when it works it's very, very fast, but it fails about 5-10% of the time for a whole variety of reasons and so any app that relies completely on it is likely to be an unreliable app.

    You can't use 3G and wifi at the same time - the device will connect to one network at a time.

    If your app absolutely 100% needs to receive the messages, I think you have no alternative than to build your own polling, but perhaps do a slow poll to reduce the resource usage, so your app always works, but push simply adds the benefit of speed.