How to send Device to device notification by using FCM without using XMPP or any other script.?

Vishal Patoliya ツ picture Vishal Patoliya ツ · Jul 18, 2016 · Viewed 21.2k times · Source

Is there any way to send Upstream notification message through FCM from one android device to another devices connected with Firebase database.

I know that XMPP server can then receive the upstream messages and send the notifications to the other devices.To receive messages sent with the upstream API i need to implement an XMPP server but there is any other way???

Answer

Diego Giorgini picture Diego Giorgini · Sep 1, 2016

Is there any way to send Upstream notification message through FCM from one android device to another devices connected with Firebase database?

Currently it's NOT possible to send messages directly from one device to another.
(or at least it's not possible without introducing a HUGE security vulnerability: more details below)

Full details:

  1. Sending messages to a user device is a pretty serious action!
    based on the payload a message can result in spam, phishing, execution of internal methods.
  2. You want this operation to be allowed only be trusted entities, this is why the FCM send API requires the SERVER-API-KEY in the authentication header.
  3. Adding the SERVER-API-KEY in your app code (or communicating it to the app in some other way) IS NOT SAFE. This because apk can be extracted, decompiled, inspected, executed on emulators, executed under debugging and so on.

The best way to implement this today: is to have some sort of server between the two devices:

[DeviceA] -- please send message to B -->  [SERVER] -- fcmSendAPI --> [DeviceB]

The server can be as simple as a PHP page, or a more complex XMPP implementation.

An example in Node.js can be found here:
Sending notifications between devices with Firebase Database and Cloud Messaging