Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Messaging device id: multiple user in same app in same device

Is there a way to create a registration id with scope of logged in user. I have an app which allows user to login as different user (say one user as student and other as a parent). User can switch between the users. Case is somewhat similar to gmail app where multiple email ids can be logged in at same time.

The issue is when we call

 FirebaseInstanceId.getInstance().getToken()

It will give the device id for that app instance. So if i am to target a specific user logged in i cannot.

One way i can accomplish targeting a user is to send user_id explicitly as data, which in my case is not efficient as it will take to send one FCM send request for each user. Is there anyway this can be accomplished. Would like to know how gmail is handling user specific notifications.

like image 284
ismathullah Avatar asked May 30 '17 09:05

ismathullah


1 Answers

Token (reg id) is intended to represent a mobile device.

As you've said you can send in payload or in tags which user the push notification is destined to, check if it is the same as the current logged in user and decide whether to create the notification or not.

The only problem here may be, how to identify the current user if at the moment of push arrival your application is killed or all users are logged out. I think in this case the solution depends on privacy level of the pushed data.

like image 186
naXa Avatar answered Sep 19 '22 11:09

naXa