0
votes

my question is the same as this one:

android device specific push notifications by using azure mobile services

But I'm using .Net backend. This is the part where I send the notification:

Dictionary<string, string> data = new Dictionary<string, string>() { { "message", "this is the message" } };
GooglePushMessage message = new GooglePushMessage(data, TimeSpan.FromHours(1));

Services.Push.SendAsync(message);

but there is no way to pass in the registration ID.

UPDATE

I've also tried using the payload property of GooglePushMessage:

 GooglePushMessage message = new GooglePushMessage();
 message.JsonPayload = JsonConvert.SerializeObject(new { registration_id = "blablabla", data = new { message = "77" } });

It turns out that it is ignoring the registration_id property, because I'm still getting the notification on my device.

What I want to achieve is to get API calls from third parties and use the registration ids that I have stored in my DB to send notifications to specific devices.

1
You have to include registration_id inside that JSON object(I guess, the message is the JSON object).User007
Including the registration_id in the JSON object doesn't change the result, I can set a random registration_id and I still get the notification on my device.DevMonster
Thats interesting. Unless you specify registration_id in json, GCM won't send notification to all. There must be a problem in sending JSON object. Please check the message content while sending to GCM.User007
I've tried assigning the payload directly. This is what I have used (literally): {"registration_id":"blablabla","data":{"message":"77"}}. With this payload I'm still getting a notification on my device. I don't understand how is this possible.DevMonster
See this tutorial for more guidance: azure.microsoft.com/en-us/documentation/articles/…lindydonna

1 Answers

3
votes

Mobile Services uses Notification Hubs to handle it's push notifications. Notification Hubs filters push (i.e. does targeted push to specific devices, users, etc) using a Tag system. So if you want to be able to push to a specific Android Registration ID, when the device registers for Push Notifications with your Mobile Service, you should specify tags that you want to tie your registration to like so:

ToDoActivity.mClient.getPush().register(gcmRegistrationId, "tag1", "tag2");

If you want to push based off of the registration ID, you'd use that ID as one of your tags. Then from your .NET backend, when you call SendAsync, you can specify a tag (or tag expression) to target a specific device. So our call to push becomes:

Services.Push.SendAsync(message, registrationID);

The above text was incorrect. Tags are limited to 120 characters (https://msdn.microsoft.com/en-us/library/dn530749.aspx) and the GCM registration ID is too long for this. TODAY you're stuck with using an alternate tag that is less than 120 characters. If you have a UserID that is known on the device you could use that as a tag and then from your backend you can push to that specific User ID. Alternatively, you could generate a GUID on app launch and use that as a tag and then from your backend push to that GUID whenever you wanted to reach the specific device.