java - 单击推送通知时打开应用程序
问题描述
我有一个 Ionic 应用程序,它通过 FCM 接收推送通知。问题是当应用程序不在前台并且我单击状态栏上的通知时,应用程序将无法打开(尽管执行了 on('notification') 的操作)。这是我的移动应用程序代码:
this.pushNotifications.on('notification').subscribe((data: any) => {
if (data.additionalData.foreground) {
alert('Ai primit un mesaj nou');
}
this.events.publish("gotMessage");
});
注意this.events.publish("gotMessage");
执行。
这就是我通过 Java 发送通知的方式:
Map body = DataMap.map(
"registration_ids", tokens,
"data", DataMap.map(
"content-available", "1",
"title", "Fmcg Reporter",
"body", "Ai primit un mesaj nou",
"sound", "default"
),
"collapse_key", "FmcgReporter"
);
Map headers = DataMap.map(
"Authorization", "key=" + key,
"Content-Type", "application/json"
);
Strings.readMethodURL("POST", "https://fcm.googleapis.com/fcm/send", headers, Strings.toJSON(body));
解决方案
确保在使用服务器发送推送通知时指定“click_action”。下面是我的 node.js 服务器的一个工作示例:
// method: "POST",
//url: "https://fcm.googleapis.com/fcm/send",
// get the key from Firebase console
headers: { Authorization: `key=${fcmServerKey}` },
json: {
"notification": {
"title": "Message title",
"body": "Message body",
"click_action": "URL to your app?"
},
// userData is where your client stored the FCM token for the given user
// it should be read from the database
"to": userData.fcmRegistrationKey
}
推荐阅读
- windows - Windows CMD 批处理脚本 - 如何避免剪切标记“!” 在循环
- php - WooCommerce 自动将特定用户角色的订单设置为“已完成”状态
- r - 删除额外的空格并在特定符号后添加空格
- tensorflow - 使用 tfhub 模块时冻结 BERT 层
- flutter - 通知正文为空 onResume app flutter firebase
- python - 命令行 - 编写可以由“-help”调用的 Python 程序的描述
- marklogic - 如何使用 ml-gradle 在 marklogic 中创建 FIELD?
- google-api - G Suite Drive API:为什么我无法获取特定文件的权限?
- python - 使用 python 将数据帧加载到 oracle db
- python - 为什么我得到的对象在 python tkinter 中没有属性错误