android - Firebase API 推送不会在 Android 设备上打开后台应用程序
问题描述
Firebase API 从后端推送有效负载:
{
"registration_ids": [
"IKSiok9Zpip5cDcebQ67wc7TnpDuhMAFJm1xdGGI44s48JbXEu5iYa"
],
"notification": {
"body": "Push Test Facility Category",
"title": null,
"icon": "myicon",
"sound": "mySound",
"vibrate": 1,
"Badge": 1,
"click_action": "FCM_PLUGIN_ACTIVITY"
},
"data": {
"message": "Push Test Facility Category",
"title": null,
"b": "22",
"id": "2",
"category_name": "Restaurants",
"h": "1",
"p": 1,
"type": "2"
}
}
fcm.service.ts
fcmListeners() {
this.firebase.onNotificationOpen().subscribe(async (data: any) => {
if (data.tap) {// when user tapped the background notification
} else { // Received in foreground
}
});
}
你能告诉我为什么当我使用上述有效负载并且应用程序在后台时应用程序没有打开吗?这是 Android 设备上的行为。但在 iOS 设备上没有问题。
如果我使用 Firebase 控制台云消息(即仪表板),那么那里没有问题。即它甚至在安卓设备的后台打开应用程序。有什么线索吗?
注意:我在这里使用firebase 插件。
解决方案
问题是该FCM_PLUGIN_ACTIVITY
活动可能未在 中定义,AndroidManifest.xml
或者如果在此处定义,则可能无法正确实施。
为了修复它,不要click_action
在通知的有效负载中指定—— 默认情况下,通知将使用MainActivity
并且将打开应用程序。
{
"registration_ids": [
...
],
"notification": {
...,
"click_action": "FCM_PLUGIN_ACTIVITY" // <--- Remove this
},
"data": {
...
}
}
推荐阅读
- javascript - 需要帮助添加 playVideo();
- python - 如何在我正在抓取的 div 中抓取元素?
- prettier - Prettier/VSCode 打破了语法
- ios - 根据 ui 堆栈视图内容自行调整表视图单元大小
- firebase - Firebase 函数不会在不同的类上初始化管理员
- javascript - 如何防止下载管理器从
- python - 如何将整个浮点数转换为整数?
- github - 防止非空命名空间删除
- spring - Spring Cloud Kubernetes 未加载具有 xx.yy 等模式的密钥
- java - 如何将 AdMob 添加到 AndroidStudio 4.2.2?