To Subscribe to a topic in an android client we should call:
FirebaseMessaging.getInstance().subscribeToTopic("news");
I want to know what happens if the internet connection is not available at moment that this instruction is executed?
Will google services automatically retry to do subscription when Internet connection become available or we developer should handle this case?
Ensuring registration token freshness To cover all cases, you should adopt a threshold for when you consider tokens stale; our recommendation is two months. Any token older than two months is likely to be an inactive device; an active device would have otherwise refreshed its token.
The FCM backend receives the message request, generates a message ID and other metadata, and sends it to the platform specific transport layer. When the device is online, the message is sent via the platform-specific transport layer to the device. On the device, the client app receives the message or notification.
For Android, you can send up to 240 messages/minute and 5,000 messages/hour to a single device.
If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.
Update:
subscribeToTopic()
now returns a Task<Void>
so you could attach an OnCompleteListener()
to check if it is successful or not.
Update:
So it seems there's more to subscribeToTopic, as per @DiegoGiorgini's comment in your previous post:
subscribeToTopic
will keep retry on background, but it's tied to your app lifecycle (not to google services, yet). So if your app is killed it will stop retrying until the app is open again. (the action is stored so it will be resumed when the app is started again)
The way I was trying out before was after the given period, I will be killing the app and didn't pull it up again.
So I've tried checking this out. It seems that if the device is offline when the request for subscription is sent, it will re-try for a period of time (20-30 seconds or so?) then will stop if still not connected. The request probably reached a time-out error. But since there is no return value for subscribeToTopic(), there is no way for you to determine this via your client app. You can send in a Feature Request if you want, pertaining to this.
However, as of the moment, an approach I think that you could do is to have a checker in your client app, where if only the device is online will you send the request.
You can also check it via your app server as I've mentioned in your previous post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With