问题
Only use of data payload not receive any notification when app is closed, and also onMessageReceive
method is not triggered.
In bellow image show data payload click here to view parameter
and Response is click here to view response
In response success 1 but not receive any notification in redmi phone.
回答1:
Supporting Fire-base push notification for all device is like a maze. There are 3 scenario for push notification
- Foreground (fire
FirebaseMessagingService
'sonMessageReceived
method) - Background (can't fire
FirebaseMessagingService
but firebase service push their message into device's Notification Tray) - App kill (can't fire
FirebaseMessagingService
firebase service push push their message into device's Notification Tray)
NOTE: Some chinese device like Xiaomi, Asus, Huawei etc. are force stop your app when you swipe out from your background stack, so that the service is kill. For that reason firebase service is not run and can't push their notification into Notification tray.
In Xiaomi - security-->permissions-->autostart then check mark your app. Enable this means app's any service always run in background. Then you get all kinds of notification from your app every time.
If you want to learn more about that, Check that and if you want to go particular device's security page from your app then check this.
回答2:
Send data message and use onMessageReceived
function to display the notification manually.
回答3:
when you omit priority
field in the JSON the default will be normal and that means firebase will send you the push whenever is appropriate.
and usually when your app is closed it takes more time to receive the message than when its foregrounded.
so if you are testing you can use "priority":"high"
to get things done quicker.
but remember to remove the field as it has high battery consumption for the end user
one more thing to consider is that on some devices (like Huawei) you have to make the app as trusted to use more power if this is the case you can do this under the power settings
Update
sending a push to a token sometimes wont work properly (since token change quickly during development time) and it's hard to verify token every time it refreshes.
So every time I'm testing the push I rather use a topic/package as "to"
parameter.
In case you subscribe your app to a topic you can check the working fellow using dashboard which suggests all the topics your app has subscribed to.
来源:https://stackoverflow.com/questions/51334341/notification-not-showing-when-the-app-is-closed