In my Android App, there are multiple users using it and they might be logged into it in different times.
I'm using Cloud Functions to send notifications to specific tokens, which means to specific devices, but I couldn't find a way to make sure that the notification will be shown only to the user it was sent to.
Let's say that users A and B are logged in to my app on the same device. The received notification is meant to User A, but the currently logged user is User B, and I don't want User B to see User A'snotifications.
I have tried to check it this way in my FirebaseMessagingService:
String receiverEmail= remoteMessage.getData().get("sendTo");
String loggedEmail=firebaseUser.getEmail();
if (loggedEmail!=null){
if (receiverEmail.equals(loggedEmail)){
sendNotification(
context.getString(R.string.your_friend_request_was_accepted),
context.getString(R.string.by)+" "+senderName);
}
}
and it works, only when the app is running. It doesn't work when it's closed.
I have also tried to get the logged user from the Shared Preferences and check it, but then loggedEmail was null, and it didn't work at all.