Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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???

like image 458
Vishal Patoliya ツ Avatar asked Jul 18 '16 08:07

Vishal Patoliya ツ


People also ask

How do I send FCM push notifications?

FCM also has a Console where you can send the Message/Notification from, without having your own app server. NOTE: Creating your own app server is up to you. Just stating that you can send a message/notification via the console. The URL used is "https://android.googleapis.com/gcm/send".

Can I send push notifications without FCM?

Without FCM, you'd need to build more than three notification systems. You'd need one each for iOS and Android, but then you'd also need to accommodate all the different types of browsers for the web application to deliver push notifications without a hitch.

How do I send FCM messages manually?

For sending FCM notification payload you can use Firebase Cloud Messaging Tool in firebase console. And click on Send your first message. Then enter the Title and body field. If you wish to send it to a particular device then click on Send test message and enter the FCM registration token.


2 Answers

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

like image 145
Diego Giorgini Avatar answered Oct 21 '22 05:10

Diego Giorgini


Finally, after 2 months of trying to maintain reliable server script myself, I suddenly found OneSignal. It's completely free, supports device-to-device push messages on iOS, Android, WP and browsers.

Hope, I won't get flag for promotion spam, but it's currently the only (and easiest) way to be completely "backendless".

Also, it's completely secure way. Nobody can send push unless he knows special OS user id, which you can store in Firebase Database protected by rules.

UPD: It's not a replacement for Firebase. It has only push service and nothing else

UPD2: Firebase now has Functions, and examples of it usage has sending FCM. You now don't need any other server or service. Read more in official samples https://github.com/firebase/functions-samples

like image 3
Dima Rostopira Avatar answered Oct 21 '22 05:10

Dima Rostopira