skip to Main Content

I want to send a notification from Firebase to a specific Flutter mobile device.

The logic (in pseudocode) would look like this:

Firebase function onSomethingHappening (interestedCientId){
  writeToFirestore // this part is easy
  notifyClientDevice (interestedCientId)
}

I know Firebase has Messaging ability, but it seems to broadcast the message to all devices.

Is there a way through Messaging (or any other Firebase means) to send a message to a specific device?

2

Answers


  1. Is there a way through Messaging (or any other Firebase means) to send
    a message to a specific device?

    Yes, have a look at the "Send messages to specific devices" section in the Firebase Cloud Messaging documentation.

    Login or Signup to reply.
  2. to send push notification to a specific device your have to get the FCM token from devices ad save that Token somewhere in the server or in firebase realtime or firestore. then you can send notification based on the that token to that specific device.

    Please read the following documentations:

    https://firebase.flutter.dev/docs/messaging/notifications/

    https://firebase.google.com/docs/cloud-messaging/flutter/client

    Here is the simple code

    FirebaseMessaging.instance.onTokenRefresh
        .listen((fcmToken) {
          // TODO: If necessary send token to application server.
          // Note: This callback is fired at each app startup and whenever a new token is generated.
    
        })
        .onError((err) {
          // Error getting token.
        });
    

    with this token you can send notification form firebase console or the this API

    https://fcm.googleapis.com/fcm/send
    
        {
            "to": "YOUR_FCM_TOEKEN",
            "notification": {
                "title": "HI DEVELOPER I AM TEWST",
                "body": "Hi DEVELOPER"
            }
        }
    

    METHOD FOR THIS IS POST

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search