【问题标题】:Flutter - When FCM push notification is clicked it's not launching app by default when app is the backgroundFlutter - 单击 FCM 推送通知时,当应用程序是后台时,默认情况下它不会启动应用程序
【发布时间】:2020-06-11 00:40:46
【问题描述】:

我目前使用 FCM 向我的颤振应用推送通知。

当应用处于后台时,当用户点击通知时,我尝试启动应用

当我尝试点击通知时收到此终端日志

    E/FirebaseMessaging(24830): Notification pending intent canceled

我还把它作为official 文件放在我的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' } 
    }  

我错过了什么?

【问题讨论】:

  • 你能解决这个问题吗?我也有同样的问题。
  • 删除 click_action 为我解决了这个问题。

标签: flutter firebase-cloud-messaging


【解决方案1】:

首先,您的有效负载应编码为 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', 并检查其工作与否

【讨论】:

    猜你喜欢
    • 2019-05-21
    • 2016-12-07
    • 2019-01-11
    • 2021-06-06
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 2021-04-19
    • 1970-01-01
    相关资源
    最近更新 更多