Based on your comment that you want to have "only informative push notifications", unfortunately, you cannot force the phone to show your notifications every time. This doesn't come as a limitation to either Xamarin, or even Azure Functions in that matter. Even some of Google's own applications behave the same.
Looking at Doze checklist:
If your users must see a notification right away, make sure to use an FCM high priority message
Even if we look at Using FCM to interact with your app while the device is idle:
FCM is optimized to work with Doze and App Standby idle modes by means of high-priority FCM messages. FCM high-priority messages let you reliably wake your app to access the network, even if the user’s device is in Doze or the app is in App Standby mode. In Doze or App Standby mode, the system delivers the message and gives the app temporary access to network services and partial wakelocks, then returns the device or app to the idle state.
So far it all looks like that if you decide to use High priority messages, everything should work fine. However, that's not the whole story. You are correct in setting the priority to high "priority":"high"
. Unfortunately, there are some caveats to this setting (from docs):
High priority messages generally should result in user interaction with your app or its notifications. If FCM detects a pattern in which they don't, your messages may be de-prioritized.
What this means is that if you are sending only an informative notification, it won't be enough to wake the device from Doze mode and show the notification. There checks/restrictions got even tighter from Android P. Read about app standby buckets here.
The good thing is that exiting Doze mode comes in a form of various events/interactions:
As soon as the user wakes the device by moving it, turning on the screen, or connecting a charger, the system exits Doze and all apps return to normal activity.
At least on the phones that I have tried, in a normal every-day scenario, the notifications are being suspended during either your night sleep, or when the device is sitting there without any interactions/movements, etc.
However, if you really need to deliver every notification and it is crucial to the UX, then you have 2 options:
- If you want to have no user interaction - set the priority to high and simply hope that the system will occasionally show some of the notifications (during the maintenance window probably). Not the best way, but by default it may work from time to time.
- If you want to guarantee that the notifications will pop-up, then have some screen describing the issue to the user and then navigate the user to
Settings -> Apps & notifications --> Advanced --> Special app access --> Battery optimisation
. Then he/she can select your app and manually set it to Don't optimise. Keep in mind that this is not considered a best practice and: a) the user shouldn't know about the consequences from this action and b) it is better to leave everything to the OS in order for it to work as intended.
To sum up, you don't have to set your notification's priority to high, because the OS will see that it a simple informative notification and it will now wake the phone. Keep in mind that, when the phone goes into "deep sleep" Doze mode, it shouldn't and mustn't wake for an informative notifications, so there's no point in trying - that's by design. Otherwise, every other developer can set its notification priority to high and the phone may never go to Doze mode, which will make the feature useless.