简体   繁体   English

当通过fireBase收到推送通知时,IONIC2在android后台应用程序时增加徽章

[英]IONIC2 Increment badges while app in background on android when push notification is received via fireBase

I have a Ionic3 app using firebase and cordova-plugin-badge.我有一个使用 firebase 和 cordova-plugin-badge 的 Ionic3 应用程序。 If the app is running in the foreground and I receive a push notification the badge number is increased.如果应用程序在前台运行并且我收到推送通知,则徽章编号会增加。

import { Badge } from '@ionic-native/badge';
declare let FCMPlugin;

constructor(private badge: Badge) {
  this.platform.ready().then(() => {
    FCMPlugin.onNotification((data) => {
      this.badge.increase(1); // works when app is in foreground
      if (data.wasTapped) {
        //Notification was received on device tray and tapped by the user.
        this.handleNotificationsWhenInBackground(data);
      } else {
        //Notification was received in foreground. Maybe the user needs to be notified.
        this.handleNotificationsWhenInForeground(data);
      }
    },
    (msg) => {
    },
    function (err) {
    });
  });
}

I receive the push notification when the app is in the background but badge number is not incremented.当应用程序处于后台但徽章编号未增加时,我会收到推送通知。 If I click on the push notification received on android while the app is in the background then badge number is incremented.如果我在应用程序处于后台时单击在 android 上收到的推送通知,则徽章编号会增加。 So the code to increment the badge number is called only when the app is in foreground.因此,仅当应用程序处于前台时才会调用增加徽章编号的代码。

My problem is: how to increment the badge number while the app is in the background and I receive a push notification.我的问题是:当应用程序在后台并且我收到推送通知时如何增加徽章编号。

唯一的方法是在你的通知负载中设置一个属性,就像你在 Android 上一样,你必须设置"click_action":"FCM_PLUGIN_ACTIVITY"属性以在用户点击通知托盘后启用一些操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase 在 android 中从后台删除应用程序时未收到推送通知 - Firebase push notification not received when app remove from background in android 应用程序在前台时收到的推送通知与应用程序在后台时收到的推送通知不同 - Push notification received while the app is in the foreground is different from push notification received when the app is in background Android Firebase 后台未收到推送通知? - Android Firebase Push notification not received in background? Android:当应用未运行或在后台运行时,将Firebase推送通知保存到磁盘 - Android: saving a Firebase push notification to disk when the app is not running or in background 应用程序在后台时,Android Firebase推送通知 - Android-Firebase Push Notification when app is in background 收到推送通知时打开Android应用 - Open Android App when Push Notification is received 未收到Android Firebase推送通知 - Android Firebase Push Notification not received 当应用程序在后台时更新Firebase推送通知 - Updating Firebase push notification when app is in background 带有来自服务器(php)的图像的 Android Firebase 推送通知未在通知中显示图像,而应用程序在后台 - Android Firebase Push Notification with image from server(php) not showing image in notification while app in background Android:Firebase 应用程序在前台时推送通知不同的图标,而当应用程序在后台时,另一个图标 - Android: Firebase push notification different icon while app is on foreground and another while app is on background
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM