Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Firebase Notifications from website to Android [closed]

What is the best way to send push notification to all of my users in Android. I have Firebase and now I'm using their backend website, but I want to do it by php or something.

like image 686
Oriol Lopez Avatar asked Oct 19 '22 06:10

Oriol Lopez


1 Answers

There is no way to send notifications to all users except using Firebase Console, see image:

Firebase Console

However if you are planning to do it by your own curl requests, then you should have planned it earlier. To do so you have to save the registration tokens of all users on your server. As of now, Firebase neither provide you the list of all registered tokens nor a way to send a push message to all users.

Curl request to send notification to multiple users, it will be delivered directly in onMessageReceived() method.

HTTP POST Request

https://fcm.googleapis.com/fcm/send

Content-Type:application/json

Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

{ "data": {
    "score": "5x1",
    "time": "15:10"
  },
  "registration_ids" : [
    "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "bk3RNH0adsf:CI2k_HadfasdoDKCIZvvDMExUdFQ3P1..."
    ]
}
like image 132
Hisham Muneer Avatar answered Nov 01 '22 15:11

Hisham Muneer