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

2023-07-28移动开发问题
0

本文介绍了当设备屏幕关闭时,如何处理 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 通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何在 COCOS2d Android 中使用 CClistview?
How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)...
2024-08-12 移动开发问题
5

cocos2d-android:如何显示分数
cocos2d-android: how to display score(cocos2d-android:如何显示分数)...
2024-08-11 移动开发问题
7

Sqlite 数据库未从资产文件夹 Android 复制
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)...
2024-04-15 移动开发问题
8

SQLite 数据库副本在由设备而不是模拟器生成时出现损坏
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)...
2024-04-15 移动开发问题
4

安卓文件拷贝
Android file copy(安卓文件拷贝)...
2024-04-15 移动开发问题
6

Android如何在android中检测Edittext的Copy事件
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)...
2024-04-15 移动开发问题
5