I sent the following notification json request to FCM gateway:
https://fcm.googleapis.com/fcm/send
And the following is the json request:
{ "data": {"body": "Nice to meet you!"},"to" : "dWgg2uGMlrs:APA91bFWhoMvV2WIZrYlENUqHzP0J2fXTuBGo-FiFd-YwGUT6vqyTjeGiOi28rOnU6MQggDwziQ7Xwg4mw6Fbnjo4-OqfOKsfw1M4E6w2rRxc0yQyGbKhQEGpIGC2eIc2CACYrEudsxz","priority" : "high"}
And the following is FCM gateway response
{"multicast_id":7757558437981419128,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1489893859089718%f58ec05df9fd7ecd"}]}
However, my my phone is not able to receive the notification. If I use the exact same device token dWgg2uGMlrs:APA91bFWhoMvV2WIZrYlENUqHzP0J2fXTuBGo-FiFd-YwGUT6vqyTjeGiOi28rOnU6MQggDwziQ7Xwg4mw6Fbnjo4-OqfOKsfw1M4E6w2rRxc0yQyGbKhQEGpIGC2eIc2CACYrEudsxz and send notification in FCM web console https://console.firebase.google.com
I am able to receive the notification.
Why?
Never mind. The request and response are totally valid. There was a bug in my android app. Issue closed.
Related
I am trying to set up AWS SNS push notifications in my iOS App. My question pertains to sending a notification request to SNS from iOS to an Android endpoint. When I try to send a notification request I get the following error.
Message=Invalid parameter: Message Reason: Invalid notification for protocol GCM: data/notification payload is malformed.
I think it may be because I am not converting the Android device token correctly for the request payload. I am trying to do it the way I send iOS to iOS notification request but the same approach does not work and results in the error above. Does the device Token need to be converted to hexadecimal? Is the format of GCM Payload correct and do we need to do anything related to device token generated. Below is a typical Android device token and my notification payload setup for referen. Please advise?
Android device token
("eV6Hxl-1RpizD0uLQiUDLi:APA91bFtlJB4QNV5_J44loN3icHLc63DvhxYuhd2_XEi--1CJxcJAKhQYKOdOWipdeHiRhk455JrBlFSoj2AubbCSfEiZaG1gw3gKKHe0ZUXpBXkcXopwy3lOcybWnHXxz8BVdUa6xIh")
GCM Payload I am using is
func gcmPayload(message: String,flagName: String, requestId: String, flagId: Int) -> [String: Any]{
var payLoad = [String: Any]()
payLoad = ["GCM":"{\"data\":{\"title\":\"\(message)\":\"body\":\"\(flagName)\":\"flagId\":\"\(flagId)\":\"requestId\":\"\(requestId)\"}:\"priority\":\"high\"}"]
return payLoad
}
My push notification works for iPhone devices using APNS. There I convert the deviceToken generated to Base64 in hexadecimal format, but this does not seem to work for Android device token values. Also, when I try to publish the message to SNS, I get an error message that states Message=Invalid parameter: Message Reason: Invalid notification for protocol GCM: data/notification payload is malformed.
Can i send push notification to topic using FirebaseMessaging.getInstance().send ?
There are a lot of answers describing how to do this using https request. It's clear, but I don't want to use large block of code, building JSON request body, adding custom headers with my key, etc.
So, what I have tried:
At first - FirebaseMessaging.getInstance().subscribeToTopic("test")
then
RemoteMessage rm = new RemoteMessage.Builder("test")
.addData("message", "Hello")
.build();
FirebaseMessaging.getInstance().send(rm);
where test is my topic.
Result: no message received. But when I send this JSON via postman:
{"to": "/topics/test",
"data": {
"message": "Hello",
}
}
everything is OK and i receive notification on my phone.
So, do FirebaseMessaging.getInstance().send support sending topic messages and how do i need to configure RemoteMessage?
I'm creating a basic Guest Service Request system with the use of Yii2 which has a function of when there's a new request that was inputted to the system the employee phone will be notified.
How do I create a firebase notification in Android, I don't really have any ideas but I do have some basic knowledge when it comes to Android developing.
Some basic steps:
Add the Firebase SDK in your Android application.
Get the authorization key.
Get the registration token for the client app instance.
Send the registration token to the server.
Send HTTP request in Yii anytime you want to send the notification:
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=Your_Authorization_Key
{
"registration_ids": ["registration_token"],
"data": {
"message": "This is a Firebase Message!",
}
}
Receive notification in Android app.
I'm using firebase console and can send only Notification messages using it.
Is there a way to send data messages using the same?
The Firebase Notifications Console can only be used to send notification messages. It cannot be used to send data messages.
See the table in message types in the Firebase documentation:
Notification message
Use scenario: FCM automatically displays the message to end-user devices on behalf of the client app. Notification messages have a predefined set of user-visible keys.
How to send:
Use your app server and FCM server API: Set the notification key. May have optional data payload. Always collapsible.
Use the Notifications console: Enter the Message Text, Title, etc., and send. Add optional data payload by providing Custom data in the Notifications console. Always collapsible.
Data message
Use scenario: Client app is responsible for processing data messages. Data messages have only custom key-value pairs.
How to send:
Use your app server and FCM server API: Set the data key only. Can be either collapsible or non-collapsible.
You can test both notification message and data message using Postman(rest client for testing http request).See screen shots:
In header pass:
key:Content-Type, value:application/json
key:Authorization:key=<Server key>
Please look here: Firebase push notifications update DB, my post from June.
In conclusion, you need send HTTP POST request to https://fcm.googleapis.com/fcm/send
https://fcm.googleapis.com/fcm/send
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{ "data": {
"score": "5x1",
"time": "15:10"
},
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
You can now send notification message via the console. Note that it is different from data messages; notification messages only trigger the onMessageReceived callback when the app is in the foreground.
They are inside the advanced options tab on the compose message screen.
Just expand it and type your key/value map.
These will be included into the data field of the notification.
let me explain my requirement, I want to send a notification to my users on their(Android) when any changes happen on table.
Using SAP NW Gateway I could able to send notification to any listener(listener class)when my table record updated/deleted.
Now I want to send this notification to users android devices,I have seen GCM but not able to understand how can I post my notification received to GCM and send that message from GCM to Android devices.
Please let me know if I can post my notification details to GCM how to send(read the sent message over GCM) to devices.
Notifications(using SAP Gateway) I am receiving is in XML format.
Thanks
Rajesh
To send a message, the application server issues a POST request to https://android.googleapis.com/gcm/send
Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
"registration_ids" : ["APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."],
"data" : {
...
},
}
Contents of data lands on connected GCM clients. Of course, you must first configure GCM API in your google developer's console.
https://developer.android.com/google/gcm/server.html
https://developer.android.com/google/gcm/http.html