flutter - Flutter - 单击 FCM 推送通知时,当应用程序是后台时,默认情况下它不会启动应用程序
问题描述
我目前使用 FCM 将通知推送到我的颤振应用程序。
当应用程序处于后台时,当用户点击通知时,我尝试启动应用程序
当我尝试点击通知时,我得到了这个终端日志
E/FirebaseMessaging(24830): Notification pending intent canceled
我也把这个放在我AndroidManifest.xml
的官方文档中
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
这是我的推送通知的有效负载
{ notification:
{
title: 'title',
body: 'body',
badge: '1',
icon: 'https://miro.medium.com/max/11400/1*lS9ZqdEGZrRiTcL1JUgt9w.jpeg',
click_action: 'FlUTTER_NOTIFICATION_CLICK',
sound: 'default'
},
data: { type: '4' }
}
我错过了什么?
解决方案
首先,您的有效负载应编码为 JSON :
{
'notification': {
'body': 'this is a body',
'title': 'this is a title'
},
'priority': 'high',
'data': {
'click_action': 'FLUTTER_NOTIFICATION_CLICK',
'id': '1',
'status': 'done'
},
'to': await firebaseMessaging.getToken(),
}
在此之后尝试'click_action': 'FLUTTER_NOTIFICATION_CLICK',
从您的有效负载中删除并检查其工作与否
推荐阅读
- laravel - Laravel 架构列
- c# - 如何在 C# 运行时更改用户控件的控件属性?
- react-native - React Native Flatlist zIndex 不适用于溢出:iOS 上的“可见”
- google-apps-script - 谷歌脚本更改事件排队
- python - 如何以另一种方式在 numpy 中创建二维数组?
- bitbucket - 使用 redhat openshift 注册 bitbucket 私有存储库的问题
- android - 设置状态栏时视图隐藏
- ajax - 如何解决这个错误(Uncaught TypeError: Cannot read property 'aDataSort' of undefined)?
- c# - 如何在 ASP.NET MVC 中编辑分组行
- reactjs - 在 react redux 之间传递/编辑数据