Getting Bad Request (400) on Azure Notification Hub's "Test Send" - android

I'm trying to send the following payload to a specific device (which is why I'm using the registration_ids) via Test Send on Azure's Notification Hub, but I'm getting a bad request error.
{
"registration_ids" : ["2670873167838193734-9582072870486547213-1"],
"data":{"message":"Hello World!"},
}
I'm not sure why since I checked the formatting and it looked fine to me based on other sources I saw.
Does anyone have an idea on what's happening?
EDIT:
Here's how I eventually managed to send a notification to a specific user:
on the client side (Java), I replaced the line
hub.register(regid)
with
hub.register(regid,"myTag")
Where "myTag" can be any other string tag you want. That way you can enter the word myTag in the 'Send to Tag' on Azure's Notification Hub and verify that you received the notification on your device.
Also, if you want to send the notification from the server side (C#), you'll need to add this header to your http request:
request.Headers.Add("ServiceBusNotification-Tags", "myTag");
Hope this helps anyone.

registration_id would not be part of the payload (see https://msdn.microsoft.com/en-us/library/azure/dn223273.aspx request body) although it is part of GCM's payload. To send to a specific device, you will need to tag that device with an id of sorts (e.g. registration_ids) and send to the tag "{registration_id}".

This is due to registration_ids field in the payload. Notification Hub does allow passing the registration_ids in the payload. Notification Hub internally substitute the registration id (before sending to GCM/FCM) based on selected devices.
https://msdn.microsoft.com/en-us/library/azure/dn530749.aspx
Thanks,
Sateesh

Related

Push notification not being sent from loopback

I have used the loopback sample application "loopback-3.x" given on:https://github.com/strongloop/loopback-example-push. The correct server key was given in config, then created an application and registered a device with that application. Then I tried sending a push notification with "notifyById" method. The console shows a succes message like:
loopback:component:push:provider:gcm Sending message to ["devicetokengiven"]: {"params":{"timeToLive":3600,"data":{"message":"sfwsed","messageFrom":"sdefsdf","badge":2}}}
loopback:component:push:provider:gcm GCM result: {"multicast_id":multicast_id,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:23423555466%24324434354"}]}
It seems to be a success, but the device doesnt get any push notification. What could be the issue? Any help would be appreciated! Thanks!
Unfortunately their last release simply doesn't work with FCM. However, in their last commit they have a change which requires an object with the attributes (messageFrom and alert) and then they convert these att to body and title. Moreover, there is a PR where someone adds another notification's attributes, but I don't think it will be merged soon.
Solutions:
Reference your module to their last commit: "loopback-component-push": "git://github.com/strongloop/loopback-component-push.git#dce16d9be30d80e258c2ac5e3dc1f74276f2b0cd"and send {messageFrom: "your title", alert: "your body"}
or
Use a simple FCM node module or even a HTTP request. Will make your life much easier.

How to implement tag registration via Microsoft Azure on Android Studio

I am following instructions at :
https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-android-push-notification-google-gcm-get-started/#sending-push-notifications
Instructions say:
// If you want to use tags...
// Refer to : https://azure.microsoft.com/en-us/documentation/articles/notification-hubs-routing-tag-expressions/
// regID = hub.register(token, "tag1,tag2").getRegistrationId();
Based on that I did the following:
added regID assignment to my code
My code looks like RegistrationIntentService example via Microsoft
except the line 48
regID = hub.register(token).getRegistrationId();
is something like this
regID = hub.register(token, "tag1").getRegistrationId();
didn't really implement anything in the reference link. Reference link assumes that I have an actual server. Right now I am just testing from Azure trouble shooting test send center. (will set up server latter).
Right now from Azure trouble shooting test send center I can't send a message to 'tag1'. I know my payload is set up right but my tag is not getting registered in RegistrationIntentService.java as suggested in instructions.
Any suggestions?
Your tags are being added correctly. I have a working version with notifications that send upstream messages to tags, and the tags are created in the exact manner you describe in your question.
The problem is Azure. I have yet to find the correct way to send a payload with a tag on the test send server in Azure. The typical GCM format of
"to": "/topics/foo-bar",
"data": {
"message": "This is a GCM Topic Message!",
}
does not work. I believe this is because Azure test send server is doing something in between when it sends the request on to GCM.
When you setup your server, your tags should be working as expected.

what does gcm.notification.e=1 stand for, into push notification payload on Android?

I'm writing an Android application which receives downstream messages from a server using Google Cloud Messaging. When receiving a message with onMessageReceived I print the bundle and read this:
RECEIVED PUSH NOTIFICATION: Bundle[{gcm.notification.e=1, gcm.notification.badge=1, gcm.notification.sound=default, ..etc...
I don't understand the key gcm.notification.e in the notification payload. On Google documentation I didn't find anything like that.
Moreover, when sending the message, I usually specify both a notification payload and a data payload. Now I tried to remove the notification payload but I still receive gcm.notification.e=1
Someone can help me understand this key and find a way to remove it?
Thanks
EDIT: I found out that sending a message without the notification payload and with content_available=false (I set this to true when working with iOS) then the gcm.notification.e=1 is not received. I receive only the data payload :). However, I still want to know the meaning of this e
Maybe this e field stands for enable. If you set it to zero in your server you won't receive the notification payload on Android. For more details se my answer here.

How to post notifications to GCM

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

Is that possible to send a message with Name of sender in android GCM.?

I have developed an android application which can send and receive push messages using Android GCM. Suppose if I am sending a push message to "xyz" device from "aaa" device I am getting a push messages succesfully, but what I need is that parallelly I wanted to display the name of the device which has sent a message with respect to the body of GCM message.
Ex:
xyz:
hi test
Please suggest me on this. Thanks in advance
Regards
Anand
You can send anything in the GCM message. If you want to send the name of the sender alongwith the message, you first need to get the name of the user and save it in a variable. Then add that name with the message in the GCM message. To differentiate the name and message part of the push notification, you can encode the GCM message in a JSON format and then send it to the other user. Then you can decode the message using JSON decoder.

Categories

Resources