When device screen off then how to handle firebase notification?

删除回忆录丶 提交于 2019-12-02 23:10:21

问题


I will try to handle firebase notification when device screen off means wake up the device when a notification arrives. In my project notification divide into so may state so how I can wake up device programmatically whenever required. May also use wake lock, but when screen off then actually

    @Override
    public void onMessageReceived(RemoteMessage message) {
    }

This method not called so in this circumstances so how I can wake up the device? Can any buddy help me with this issue?


回答1:


There are two types of messages in FCM (Firebase Cloud Messaging):

Notification Messages: These messages trigger the onMessageReceived() callback only when your app is in foreground

Data Messages: Theses messages trigger the onMessageReceived() callback even if your app is in foreground/background/killed

NOTE: Be sure you're not adding JSON key notification

The following message will not call your onMessageReceived() when your app is in the background or killed, and you can't customize your notification.

{
      "to": "example",
      "notification": {
        "title" : "title",
        "text": "text"
       }
    }

but instead using this will work

{
       "to": "example",
       "data": {
           "text":"text",
           "title":"title"
       }
    } 


来源:https://stackoverflow.com/questions/44540568/when-device-screen-off-then-how-to-handle-firebase-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!