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

查看:27
本文介绍了当设备屏幕关闭时,如何处理 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 Cloud Messaging)中有两种类型的消息:

通知消息:这些消息仅在您的应用处于前台时触发 onMessageReceived() 回调

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

数据消息:这些消息会触发 onMessageReceived() 回调,即使您的应用处于 foreground/background/killed

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天全站免登陆