android - 无法使用“node fcm-notification”显示 FCM 通知
问题描述
我正在开发一个视频通话应用程序,当有来电时,用户会通过通知收到通知,并且能够单击通知开始通话。现在,当应用程序关闭或在后台运行时会推送通知,但在前台打开应用程序时不会推送。
此外,当应用程序处于后台或未运行时单击通知只会打开应用程序而不会启动视频通话。我可以开始通话的唯一方法是在应用程序处于后台/未运行时接收通知,手动打开应用程序,然后单击通知。
这是我处理通知发送的代码:
var fcm = require('fcm-notification');
var serverKey = require('./fcmKey.json');
var FCM = new fcm(serverKey);
const payloadBody = {
room,
caller,
language,
receiver
}
var message = {
token : deviceToken,
data : payloadBody,
notificaton: {
title : 'MyApp',
body: 'Somebody is calling'
}
FCM.send(message, function(err, response) {
if(err) {
console.error('Notification error: ${JSON.stringify(err)}');
} else {
console.error('Notification success: ${JSON.stringify(response)}');
}
}
我的清单还包含这样的 fcm 服务:
<service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
解决方案
您所描述的前台和后台行为正是通知类型消息应该如何工作。如果您想控制向用户显示的通知的行为,您应该从消息中删除通知有效负载,并自己构建整个事物以响应数据有效负载。您将在您创建的 FirebaseMessagingService 子类中收到该消息。
推荐阅读
- react-native - 在 TouchableHighlight 中嵌套 Button 或 TouchableHighlight
- java - java创建一个返回哈希集的函数
- c++ - RC4 未生成正确的加扰状态数组
- c++ - 如何使用数组查找标准偏差
- javascript - 如何在提交时将输入日期格式从 MM dd yy 更改/转换为 yyyy-mm-dd
- javascript - 三.js改变每个粒子的轴心点
- wpf - 在 Core 3 客户端中找不到 WithUrl()
- scala - 在 Spark scala 中读取简单 JSON 文件时将所有记录设为 NULL
- python - 如何让python只读取文本文件的内容一次
- android - 如何使用 onPause(后退按钮)发送结果 Intent