I know this might be really easy, but I can't find a good reference to start. So here is my questions. I am making an Android app that needs to send notification on button click.

Notifications could be sent to

  1. all other users that installed the app
  2. specific users that installed the app.

The sender sending the notification itself must not get the notification alert.

I want to achieve this by using Firebase Cloud Functions. But I don't know like how to start.

It'll be really helpful if someone showed snippets of Android Java code and Firebase Cloud functions code to achieve the same.

For example let's say there are three users A, B and C that installed my sample app. So if A sends a notification alert then B and C both must receive it except A. Similarly if A wants to send notification to particular user B (let's say by using B's unique user ID) then only B must receive the notification and not C.

Answer

To be able to send notifications to certain group of users with Firebase, you can write a JavaScript function that will listen for some events that triggers your database.

When this events are triggered you can perform an operation, in this case, you will need to write a JavaScript (or TypeScript) function that can find the device token to send the notification and a notification payload. This example is very clear on how to do it, and it's part of a collection of function samples on the Firebase functions repo.

https://github.com/firebase/functions-samples/tree/Node-8/fcm-notifications

  • 1
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions