当设备屏幕关闭时,如何处理Firebase通知? [英] When device screen off then how to handle firebase notification?

查看:65
本文介绍了当设备屏幕关闭时,如何处理Firebase通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当设备屏幕关闭时,我将尝试处理Firebase通知,这意味着在通知到达时唤醒设备.在我的项目通知中,可能会这样划分状态,以便我可以在需要时以编程方式唤醒设备.也可以使用唤醒锁定,但是当屏幕关闭时,实际上

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?

推荐答案

FCM(Firebase云消息传递)中有两种消息类型:

通知消息:仅当您的应用程序位于前台时,这些消息才会触发onMessageReceived()回调

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

注意:请确保您没有添加JSON密钥通知

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

当您的应用在后台或被终止并且您无法自定义通知时,以下消息将不会调用您的 onMessageReceived().

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"
       }
    }

但是使用它会起作用

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

这篇关于当设备屏幕关闭时,如何处理Firebase通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆