katzer / cordova-plugin-local-notifications

Cordova Local-Notification Plugin
Apache License 2.0
2.57k stars 1.75k forks source link

[android] Notification isn't displayed in foreground, only in statusbar #1843

Closed devjoks closed 2 weeks ago

devjoks commented 4 years ago

I installed firebase plugin (cordova-plugin-firebasex) and install this plugin. In iOS I don't have problems with the notification in foreground, but in android the notification only appears in the statusbar.

Your Environment

Expected Behavior

Show push notification by firebase when the app is in foreground.

Actual Behavior

Push notification only appears in the statusbar and isn't showing in foreground.

Context

I trying to display the notification when the app is in foreground and background with the same behavior.

aaabidunique commented 4 years ago

As I understand in foreground fcm will call the callback function and not show the notification. In Background fcm will show notification and on click it will call the call back function. It will be helpful if you post some sample regarding what exactly you are doing.

devjoks commented 4 years ago

As I understand in foreground fcm will call the callback function and not show the notification. In Background fcm will show notification and on click it will call the call back function. It will be helpful if you post some sample regarding what exactly you are doing.

I'm using the code below

  public onMessageReceived() {
    const _self = this;
    this.firebase.onMessageReceived().subscribe((data) => {
      if (data.messageType === 'notification') {
        if (_self.platform.is('ios')) {
          _self.notificationMessage = {
            'message': data.aps.alert.body,
            'title': data.aps.alert.title,
          };
        } else if (_self.platform.is('android')) {
          _self.notificationMessage = {
            'message': data.body,
            'title': data.title,
          };
        }
        _self.localNotifications.schedule({
          title: _self.notificationMessage.title,
          text: _self.notificationMessage.message,
          foreground: true,
          id: 1,
          priority: 2,
          silent: false,
        });
      }
    });
  }
aaabidunique commented 4 years ago

As I understand in foreground fcm will call the callback function and not show the notification. In Background fcm will show notification and on click it will call the call back function. It will be helpful if you post some sample regarding what exactly you are doing.

I'm using the code below

  public onMessageReceived() {
    const _self = this;
    this.firebase.onMessageReceived().subscribe((data) => {
      if (data.messageType === 'notification') {
        if (_self.platform.is('ios')) {
          _self.notificationMessage = {
            'message': data.aps.alert.body,
            'title': data.aps.alert.title,
          };
        } else if (_self.platform.is('android')) {
          _self.notificationMessage = {
            'message': data.body,
            'title': data.title,
          };
        }
        _self.localNotifications.schedule({
          title: _self.notificationMessage.title,
          text: _self.notificationMessage.message,
          foreground: true,
          id: 1,
          priority: 2,
          silent: false,
        });
      }
    });
  }

From the code you provided, I can't conclude anything. So can you provide a sample project (a repo) with this issue, it will help me fast track it.

Meanwhile You can look into https://github.com/dpa99c/cordova-plugin-firebasex#foreground-notifications

gwynjudd commented 4 years ago

Probably related to the fix in this PR

https://github.com/katzer/cordova-plugin-local-notifications/pull/1696