Sam*_*ath 0 android firebase firebase-cloud-messaging angular ionic4
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"
}
}
Run Code Online (Sandbox Code Playgroud)
fcm.service.ts
fcmListeners() {
this.firebase.onNotificationOpen().subscribe(async (data: any) => {
if (data.tap) {// when user tapped the background notification
} else { // Received in foreground
}
});
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我为什么当我使用上述有效负载并且应用程序在后台时应用程序没有打开吗?这是 Android 设备上的行为。但在 iOS 设备上没有问题。
如果我使用 firebase 控制台云消息(即仪表板),则没有问题。即它甚至在安卓设备的后台打开应用程序。有什么线索吗?
注意:我在这里使用了firebase 插件。
问题是FCM_PLUGIN_ACTIVITY活动可能未在 中定义,AndroidManifest.xml或者如果在那里定义,则可能无法正确实施。
为了修复它,不要click_action在通知的有效负载中指定- 默认情况下,通知将使用MainActivity并且这将打开应用程序。
{
"registration_ids": [
...
],
"notification": {
...,
"click_action": "FCM_PLUGIN_ACTIVITY" // <--- Remove this
},
"data": {
...
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2797 次 |
| 最近记录: |