I have successfully implemented Azure Function, which sends push notifications to NotificationHub for Android, iOS and UWP. During the testing I discovered that when Android device is in Doze mode push notification is not delivered on lock screen. It is only delivered when I unlock the phone.
I found out this stackoverflow post, which helped me to fix it with method SendFcmNativeNotificationAsync. I used this code:
string payload = @"{
""data"":{
""notificationtype"":""sap"",
""title"":""value2"",
},
""priority"":""high""
}";
await hub.SendFcmNativeNotificationAsync(payload);
However my implementation using SendNotificationAsync method which works for all 3 platforms, but not in Doze mode. This is my code to send notification:
Dictionary<string, string> templateParameters = new Dictionary<string, string>();
templateParameters["alert"] = "Test";
templateParameters["title"] = "Whosap";
var notification = new TemplateNotification(templateParameters);
await hub.SendNotificationAsync(notification);
I tried to set header of notification:
var headers = new Dictionary<string, string> { { "android", @"{""priority"": ""high""}" } };
notification.Headers = headers;
But this didn't work. Does anybody know how to set priority in TemplateNotification object and send it with SendNotificationAsync method?
This is how I force/unforce device to doze mode:
adb shell dumpsys deviceidle force-idle
adb shell dumpsys deviceidle unforce