Send Message - shaikhalvee/FCM GitHub Wiki
We use Advanced Rest Client Application.
Settings > GLOUD MESSAGING > Server key : AAAAz3lrkJk:APA91...nHi
Request URL:
https://fcm.googleapis.com/fcm/send
Header:
Content-Type:application/json
Authorization:key=AAAAz3lrkJk:APA91...nHi // Server key
Payload
{
"to": "fImrBgFR9vM:APA91bF...Vj0E" // registration_id or cleint token, see
// FirebaseInstanceId.getInstance().getToken()
"notification": {
"title": "Hello",
"body": "This is test message."
}
}
Payload:
{
"to": "fImrBgFR9vM:APA91bF...Vj0E"
"notification":{
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
"data": {
"title": "Hello2",
"body": "This is test message."
}
}
Payload:
{
"to": "fImrBgFR9vM:APA91bF...Vj0E"
"notification":{
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "ic_directions_run_white_24dp"
}
}
where ic_directions_run_white_24dp.xml is in res/drawable/
For this purpose we use tag
Payload:
{
"to": "fImrBgFR9vM:APA91bF...Vj0E"
"notification":{
"body" : "3 : 1",
"title" : "Portugal vs. Denmark",
"tag":"1",
"icon" : "myicon"
}
}
<activity android:name=".ActionActivity">
<intent-filter>
<action android:name="com.fcm.ACTION_ACTIVITY"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Payload
{
"to": "fImrBgFR9vM:APA91bF...Vj0E"
"notification":{
"body" : "4 : 2",
"title" : "Italy vs. France",
"icon" : "myicon",
"click_action":"com.fcm.ACTION_ACTIVITY"
}
}
Unfortunately, as of the moment, there is no API or even a parameter that you can use in order to schedule a notification.
Payload:
{
"to": "/topics/news",
"notification":{
"body" : "We have a news for you",
"title" : "Read this now!",
"icon" : "myicon"
}
}
Here topic is "news". To create a topic, we call in client:
FirebaseMessaging.getInstance().subscribeToTopic("news");
Payload:
{
"condition": "'news' in topics || 'radio' in topics",
"notification":{
"body" : "We have a news for you",
"title" : "Read this now!",
"icon" : "myicon"
}
}
https://android.googleapis.com/gcm/notification
Content-Type:application/json
Authorization:key=AAAAz3lrkJk:APA...XtnHi
project_id:891095322777 (Overview -> CLOUD MESSAGING -> Sender ID)
{
"operation": "create",
"notification_key_name": "appUser-Ievgen",
"registration_ids": ["fheS3m4LmoM:APA9...v7K",
"d0QCxkOrfRE:APA91...QZTOd-"] 🐪
}
Response
{
"notification_key": "APA91bHcOB3n6Dnu6rUM0m8yu3sAtTd4r...CfE" 🐙
}
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AAAAz3lrkJk:APA...XtnHi
{
"to": "APA91bHcOB3n6Dnu6rUM0m8yu3sAtTd4r...CfE", 🐙
"notification": {
"title": "Hello",
"body": "This is test message."
}
}
Response:
{
"success": 2,
"failure": 0
}
{
"operation": "remove",
"notification_key_name": "appUser-Ievgen",
"notification_key": "APA91bHcOB3n6Dnu6rUM0m8yu3sAtTd4r...CfE", 🐙
"registration_ids": ["d0QCxkOrfRE:APA91...QZTOd-"] 🐪
}
If you remove all existing registration tokens from a device group, FCM deletes the device group.