I'm setting up an android apps notification with FCM so it can trigger the app to send notification to other device(receiver) using the same app and receive the notification. I want to use FCM but without Firebase Database but instead using PostGreSQL/other DB. How to do it? also is it possible to implement Firebase in AdonisJS? because I use that for server-side.
-
have u tried something? if you have some code that doesnt work we could help you better. When a user allows messaging notification it creates a token, you can get the token back and save it somewhere, then you would need to make some logic to retrieve the user you want to push and its token and via a cloud function or similar, send the notification directly or to a topic... it is possible but complex. – andresmijares Jun 11 '19 at 18:20
-
@andresmijares I have tried to implement the fcm to android apps and I tested it from firebase console and the apps receive the notification. But I want to send notification if I do something like I giving 4 star rate to my friend and then it sent notification to my friend when it reach to him, he will receive the notification. Kinda confused how to triggered it cause so many tutorial using firebase database to explain about it – Nix Jun 12 '19 at 10:19
1 Answers
Firebase Cloud Messaging does not support directly sending messages to a device. Sending a message to a device (known as a downstream message) requires that you specify the FCM server key, and (as its name implies) that key should only be used on a server, or otherwise trusted environment.
The reason for this is that having the FCM server key for a project allows you to send any message to any and all of the devices in that project, so having this available outside of a trusted environment would be a security concern.
But there is no need to use the Firebase Database to send FCM message. The simplest way to verify this is to send a message through a command line curl call, like shown here: How can I send a Firebase Cloud Messaging notification without use the Firebase Console? You can also implement the code to send a message in Cloud Functions or your own favorite server-side environment without a database. You'll just have to pass in the target of where to send the message into the function.

- 565,676
- 79
- 828
- 807
-
After I read the documentation I still a bit confuse so I want to ask, if I triggered something to send notification for example, I'm giving a rate to my friend and I submit it then My friend received the notification that describe he has been rated by me. so does the trigger place at the server side or it can be pleased in the android? also does Firebase-Admin SDK need to be place in Server side to interact with FCM in Android? – Nix Jun 12 '19 at 10:02
-
The call to FCM to send the message happens server-side, as it requires that you specify the FCM server key. But you can call that code from Android. Many apps do this by writing the "send a notification to my friend abc" into the database, and then trigger Cloud Functions from that. But this is not required. – Frank van Puffelen Jun 12 '19 at 13:35
-
So I got something from curl that you have mentioned then I went through [here](https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html) just took half of the code and it's work for me. Thank you for answering my question. – Nix Jun 13 '19 at 09:16