5

I was wondering how I could send a push notification by code from my app, via Firebase? I am only able to send a push notification from my Firebase Notification-console as of right now, but I would like to figure out how to send one programmatically. Any ideas on where I can find more info on this? Please point me in the right direction! I tried to check out a project on GitHub by Firebase (quickstart), but I have to say that including that project, it's very little information on this. I was lucky to find a tutorial on YouTube that at least allowed me to teach myself how to use remote notifications.

Thanks in advance!

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
askaale
  • 1,199
  • 1
  • 23
  • 50
  • Sending push notifications programmatically with Firebase Cloud Messaging, currently requires that you run your message-sending code on a server. See http://stackoverflow.com/a/37634914/209103 and the [firebase documentation](https://firebase.google.com/docs/cloud-messaging/downstream#sending_topic_messages_from_the_server) – Frank van Puffelen Aug 01 '16 at 16:05

1 Answers1

4

You can, Firebase (formally Cloud Messaging) provides REST API to send push notifications, checkout the following documentation,

https://firebase.google.com/docs/cloud-messaging/downstream

https://firebase.google.com/docs/cloud-messaging/server

You have to construct the payload, generate Server API Key from Firebase Console and send http request to Firebase endpoint (https://fcm.googleapis.com/fcm/send)

And if you are looking for any library, here is the one which works

http://www.java2s.com/Code/Jar/g/Downloadgcmserverjar.htm

it will send push to GCM server, but it works with Firebase too(we are currently using it)

i don't currently find any official SDK provided by firebase to send push notifications

Ramesh Lingappa
  • 2,448
  • 20
  • 33
  • 1
    Would this allow a 'user to user' push notification feature? I am currently developing a chat-application that uses JSQMessagesViewController and I need to send a push notification for each message that is not read in the application. I know Backendless has this feature, but I am not willing to use both Firebase and Backendless (store user info in two different backends).. Basically I want to listen for incoming entries in /Recent in Firebase - and then display a push notification. – askaale Aug 01 '16 at 15:56
  • Yes as long as you know the other user push token and store server api key in your client app, yes it's possible! – Ramesh Lingappa Aug 01 '16 at 16:10
  • Thanks for the follow up, would you mind telling me a bit more in detail on how I would approach this? :) Do I have to run the server on a VPS? – askaale Aug 01 '16 at 17:26
  • It's now possible with Google Cloud Functions. See here: https://stackoverflow.com/a/47106374/144088 – Crashalot Nov 04 '17 at 01:16