HMS-Core / hms-cordova-plugin

This repo contains all of Cordova HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
99 stars 44 forks source link

onNotificationOpenedApp not triggering #21

Closed chehsing closed 3 years ago

chehsing commented 3 years ago

Description I trying to implement a navigation function by tapping notification but the onNotificationOpenedApp is not triggering when i try to tap on it. I double checked i implemented the plugins correctly.

Expected behavior onNotificationOpenedApp gets trigger with result.

Current behavior onNotificationOpenedApp not getting trigger

Other

export class HMSPushUtils {
  constructor(
    private hmsPush: HmsPush,
    private hmsPushEvent: HmsPushEvent,
    private authService: AuthService,
    private storage: StorageUtils,
  ) {
    this.hmsPush.init();
    this.initiateListener();
  }

  initialize() {
    this.hmsPush.getToken().then((hmsToken) => {
      console.log("hmsToken", hmsToken);

      this.storage
        .getStorage(STORAGE_KEY.FCM)
        .then((token) => {
          if (token == null) {
            // Send hms token to backend to be stored
            this.authService.registerFcm(hmsToken).then((result) => {
              this.checkNotificationAllowed();
            });
          } else {
            this.checkNotificationAllowed();
          }
        })
        .catch((error) => console.log("getToken", error));
    });
  }

  private initiateListener() {
    this.hmsPushEvent.onTokenReceived((result) => {
      console.log("TOKEN_RECEIVED_EVENT", result.token);
    });

    this.hmsPushEvent.onTokenError((result) => {
      console.log("ON_TOKEN_ERROR_EVENT", result.exception);
    });

    this.hmsPushEvent.onNotificationOpenedApp((result) => {
      console.log("get");
      console.log("NOTIFICATION_OPENED_EVENT", result);
      // Show logic here
    });

    this.hmsPush
      .getInitialNotification()
      .then((result: any) => {
        console.log("getInitialNotification", result);
      })
      .catch((result: any) => {
        console.log("getInitialNotification", result);
      });
  }

Environment

chehsing commented 3 years ago

I tried running my application on Android 10, it seems to be working fine. Is this function only working on Android 10 and above?

mesutgedik commented 3 years ago

Hi chehsing, First of all, I need some information to solve your issue.

If you give me these informations maybe I can help more.

For your second question's answer is onNotificationOpenedApp listener works Android 5.0 and above.

chehsing commented 3 years ago

hi mesutgedi, here's the information you requested:

I tried a few cases on the listener, so far this is what i got on my end.

Physical device (with HMS Core)

Huawei cloud debugging

mesutgedik commented 3 years ago

Hello again chehsing , we are investigating the error you encountered, we will return as soon as possible.

chehsing commented 3 years ago

Hey, i'm able to narrowed it down. This issue seems to be happening when I sent it with notification message. Changing it to data message seems to resolved the issue.

Screen Shot 2021-03-08 at 9 29 40 AM