Search code examples
androidazuregoogle-cloud-messagingazure-notificationhub

Sending high priority message via GCM on Azure Notification Hub


I'm using the AzureNotification Hub to send GCM noifications to my Android aplication. My question is by default what priority does the SDK use to send notifications and can this be configured. Based on what I have seen on Google's website https://developers.google.com/cloud-messaging/concept-options?hl=en I can simply add the priority as part of the payload. However I am not sure how the underlying SDK handles this and if it adds a priority by default. This is what I did. The notification is being sent with the code below but I'm wondering if the priority value has any effect.

var payload = new
{
priority="high",
data = new
{
message = new
{
model.Title,
model.Time,
model.Message,
model.NotificationId,
model.NotificationType,
model.SenderFacebookId,
model.TargetId,
model.TargetUserFacebookId
}
}
};

var json = JsonConvert.SerializeObject(payload);
await hub.SendGcmNativeNotificationAsync(json, Tag.UserDevice.Id);

Solution

  • The way you are adding priority (as a sibling of data) should work. The default GCM priority is normal, so if you don't assign a priority it is treated as normal. This means slightly different things on different platforms but in general high priority messages will be delivered ASAP while normal priority messages will be delivered at the next optimal time depending on various device conditions.

    On Android GCM priority helps devices decide when to deliver messages when in Doze mode. Messages that need user action like a chat message should get high priority, Android will try to deliver them ASAP. Most messages like sync new server data should be assigned normal priority, Android will try to deliver them at the next most optimal time for the device.