Ionic 5 and capacitor FCM push notification issue on android

I am developing ionic5 app and I integrated push notification using capacitor FCM push notification (https://capacitor.ionicframework.com/docs/guides/push-notifications-firebase/).

On Android i get notification alert (bannes and sound) only if app is in background mode, not in foreground or if app is closed. In the latter 2 cases, however, the pushNotificationReceived event still triggers but the notification banner does not appear and no sound. Testing on Huawei P10 Lite with EMUI 5.1 and Android 7.0

No issue on ios app, getting notifications even if I kill the ios app, background or foreground.
Am I doing something wrong?

3 Likes

i’ve done a simple “trick” because I had the same problem both on iOS and Android:

PushNotifications.addListener(
  'pushNotificationReceived',
  async (notification: PushNotification) => {


    const alert = await this.alertController.create({
      header: JSON.stringify(notification.title).substring(1, JSON.stringify(notification.title).length - 1),
      message: JSON.stringify(notification.body).substring(1, JSON.stringify(notification.body).length - 1),
      buttons: ['OK']
    });

    await alert.present();


  }
);

With this function, if the app is in background or closed, the push notification will show, otherwise it will show an alert with title and body message

1 Like

Same issue, any fix or solution ?

  private _doLocalNotif(notification) {
    Plugins.LocalNotifications.schedule({
      notifications: [
        {
          title: notification.title,
          body: notification.body,
          id: Date.now(),
          attachments: [
            {
              id: 'site',
              url: notification.data.imageUrl,
            },
          ],
          actionTypeId: '',
        },
      ],
    });
  }

With this function you can trigger you’r own notification