当我发送 Firebase 主题通知时,onMessageReceived 方法不会在应用程序处于运行状态时触发
- 背景和屏幕锁定
- 最近申请的申请已经结束
在以上两种情况下,我只在系统托盘中收到通知,我想在 sqlite 的存储中以编程方式处理它
及其在近期申请中列在前台和后台的案例应用
那么我如何获得通知,我想在 sqlite 中存储通知
我的 postman 请求如下
{
"to": "/topics/181_Red_Route",
"data": {
"sound": "default",
"badge": "1",
"title": "Title1",
"body": "Desc1"
},
"notification": {
"sound": "default",
"badge": "1",
"title": "Title1",
"body": "Desc1"
},
"priority": "high",
"content_available": true
}
提前致谢
最佳答案
https://firebase.google.com/docs/cloud-messaging/android/send-multiple
检查此链接提到,有两种方法可以发送消息有效负载。
1) 作为通知
2) 作为数据
如果服务器发送"Data" payload,那么它将在应用程序onMessageReceived() 方法中接收。您可以通过检查下面给出的有效负载在 onMessageReceived() 中管理它。
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
& 还要检查如何执行服务器代码,传递“通知”/“数据”。
https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages
关于android - 当应用程序在 android 中关闭时,是否可以将 Firebase 主题通知保存在 sqlite 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38567510/