【问题标题】:IONIC android FCM notificationIONIC android FCM 通知
【发布时间】:2017-07-01 01:41:50
【问题描述】:

在 Firebase 通知中,我在应用程序处于后台时收到通知,但是当我打开应用程序而不点击通知时,数据不会反映在 IONIC android 应用程序中。

当应用程序处于前台时,数据会自动反映。

我也使用了 cordova-plugin-messaging 插件,但没有用。

我用过

FCMPlugin.onNotification( 函数(数据){

          if(data.wasTapped){
            console.log(data);

          }else{
            console.log(data);

          }

        },
        function(msg){
          console.log('onNotification callback successfully registered: ' + msg);
        },
        function(err){
          console.log('Error registering onNotification callback: ' + err);
        }
      );

也用过:

window.cordova.plugins.firebase.messaging.onMessage(function(data) {

      console.log(data);

});

但它适用于应用程序处于前台以及我们单击通知时..

我想在应用程序处于后台时检索数据,并且在应用程序打开时不点击通知。

感谢回答

【问题讨论】:

  • 嗨。发布相关代码sn-ps。
  • FCMPlugin.onNotification(function(data){ if(data.wasTapped){ console.log(data); }else{ console.log(data); } }, function(msg){ console .log('onNotification回调注册成功: ' + msg); }, function(err){ console.log('注册onNotification回调出错: ' + err); } );
  • 如果用户在您的应用被杀死/未运行时收到通知,如果应用在没有点击通知的情况下打开,则数据不会发送到应用。这是正常行为。

标签: firebase ionic-framework firebase-cloud-messaging


【解决方案1】:

sendPushPayload( data );

Intent NotificationIntent = new Intent(this, FCMPluginActivity.class)
 .addCategory(Intent.CATEGORY_LAUNCHER)

  .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  for (String key : data.keySet()) {
  NotificationIntent.putExtra(key, data.get(key).toString());
  }
  startActivity(NotificationIntent);

将上面的代码放在你的android原生文件(MyFirebaseMessagingService.java )和cordova plugin android(src ->android-> MyFirebaseMessagingService.java)文件中,如果进行上述更改意味着应用程序在后台你推送通知意味着应用程序将自动打开。

【讨论】:

    猜你喜欢
    • 2017-05-04
    • 2017-01-12
    • 2017-02-03
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-04
    • 2017-06-13
    相关资源
    最近更新 更多