当设备屏幕关闭时,如何处理 Firebase 通知?

When device screen off then how to handle firebase notification?(当设备屏幕关闭时,如何处理 Firebase 通知?)
本文介绍了当设备屏幕关闭时,如何处理 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 通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)