Should I store Android device tokens for sending push notifications?

2k views Asked by At

I am working on an app, which requires Android push notifications to be implemented.

I have decided to use Firebase Cloud Messaging directly; without using any other abstraction such as AWS SNS or Pusher.

I would like to avoid storing and managing device tokens in the backend, by using the following approach.

In the android app.

  1. When the user logs into the android application, obtain device token but not send it to the server.
  2. Subscribe to a topic that is based on a agreed convention, such that the topic is unique to that user.
  3. On logout unsubscribe from the topic.

In the Server.

  1. Whenever a situation arises to send a notification to particular user, send push notification to the topic, that is based on the convention.

I would like to know if this is a viable strategy to avoid managing device tokens ?

Case against using topics.

From the official docs.

Based on the publish/subscribe model, FCM topic messaging allows you to send a message to multiple devices that have opted in to a particular topic. You compose topic messages as needed, and FCM handles routing and delivering the message reliably to the right devices.

For example, users of a local weather forecasting app could opt in to a "severe weather alerts" topic and receive notifications of storms threatening specified areas. Users of a sports app could subscribe to automatic updates in live game scores for their favorite teams.

I see that topics are recommended, when multiple devices are to be notified. But I have decided to create a topic per user, this would mean most topics would end up getting subscribed by only one device; Is this approach ok ?

2

There are 2 answers

7
AL. On

I see that topics are recommended, when multiple devices are to be notified

Yes, multiple devices that have something common to listen to, which is the topic. Topics are used for messages that could be received by the general clients since it is public -- i.e. anyone could subscribe and receive messages sent to it.

What is advised to use for multiple devices, but for the same user is to use Device Groups (see my answer here for tips on Managing Device Groups). However, if you don't mind the "topics being public" part, then your approach should be fine.

0
venkatarao On

Yes, Here required device tokens if we want to send push notification whoever installed your app. My research we can save device tokens in back end at first time installation of your app that is better according to my understanding so that we can easy to send push notification across all devices.