DevMonster
DevMonster

Reputation: 116

android device specific push notifications by using azure mobile services (.Net backend)

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.

Upvotes: 0

Views: 551

Answers (1)

Chris
Chris

Reputation: 3017

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.

Upvotes: 3

Related Questions