bhandaribhumin / cordova-plugin-local-notification-12

Apache License 2.0
17 stars 38 forks source link

App closes when clicking on push/notification #5

Open VndrGrhrd opened 1 year ago

VndrGrhrd commented 1 year ago

General summary of the issue.

I get the firebase object, schedule the notification, and add the click event to open a given page., however when clicking on the push/notification with the app open, it closes app and does not open again.

/*
Excuse my English, I'm Brazilian, due to this the methods in Portuguese
/

Your Environment

Ionic:

   Ionic CLI          : 5.4.16 (C:\Users\sempr\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.10-202005061940
   @ionic/app-scripts : 3.2.2

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 9.1.0
   Cordova Plugins   : cordova-plugin-ionic-webview 5.0.0, (and 19 other plugins)

Utility:

   cordova-res : 0.15.4
   native-run  : 1.7.1

System:

   NodeJS : v12.13.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.1.0
   OS     : Windows 10

others:

  "dependencies": {
    "@angular/common": "^5.2.10",
    "@angular/compiler": "5.0.3",
    "@angular/compiler-cli": "5.0.3",
    "@angular/core": "5.0.3",
    "@angular/forms": "5.0.3",
    "@angular/http": "5.0.3",
    "@angular/platform-browser": "5.0.3",
    "@angular/platform-browser-dynamic": "5.0.3",
    "@awesome-cordova-plugins/core": "^5.44.0",
    "@awesome-cordova-plugins/in-app-purchase-2": "^5.45.0",
    "@awesome-cordova-plugins/splash-screen": "^5.45.0",
    "@ionic-native/app-version": "^5.15.0",
    "@ionic-native/background-mode": "^5.15.0",
    "@ionic-native/badge": "^5.15.0",
    "@ionic-native/camera": "^5.15.0",
    "@ionic-native/core": "^5.15.0",
    "@ionic-native/device": "^5.15.0",
    "@ionic-native/diagnostic": "^5.16.0",
    "@ionic-native/fcm": "^5.27.0",
    "@ionic-native/file": "^5.15.0",
    "@ionic-native/file-opener": "^5.15.0",
    "@ionic-native/geolocation": "^5.15.0",
    "@ionic-native/market": "^5.23.0",
    "@ionic-native/network": "^5.15.0",
    "@ionic-native/social-sharing": "^5.36.0",
    "@ionic-native/speech-recognition": "^5.15.0",
    "@ionic-native/sqlite": "^5.32.0",
    "@ionic-native/status-bar": "^5.15.0",
    "@ionic-native/text-to-speech": "^5.15.0",
    "@ionic/storage": "2.1.3",
    "angular2-text-mask": "^8.0.4",
    "brmasker-ionic-3": "^1.6.3",
    "cordova": "^9.0.0",
    "cordova-android": "^9.0.0",
    "cordova-plugin-androidx-adapter": "^1.1.0",
    "cordova-plugin-app-version": "^0.1.9",
    "cordova-plugin-background-mode": "git+https://github.com/katzer/cordova-plugin-background-mode.git",
    "cordova-plugin-badge-fix": "^0.8.10",
    "cordova-plugin-camera": "^4.1.0",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-fcm-with-dependecy-updated": "git+https://github.com/LucasBitello/cordova-plugin-fcm-with-dependecy-updated-android_12_fixes.git",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-file-opener2": "^2.2.1",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-inappbrowser": "^4.0.0",
    "cordova-plugin-ionic-webview": "5.0.0",
    "cordova-plugin-local-notification-12": "^0.1.4",
    "cordova-plugin-market": "^1.2.0",
    "cordova-plugin-network-information": "^2.0.2",
    "cordova-plugin-purchase": "^11.0.0",
    "cordova-plugin-speechrecognition": "^1.2.0",
    "cordova-plugin-splashscreen": "^6.0.2",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-tts": "^0.2.3",
    "cordova-plugin-whitelist": "^1.3.4",
    "cordova-plugin-x-socialsharing": "^6.0.4",
    "cordova-sqlite-storage": "^6.0.0",
    "cordova.plugins.diagnostic": "^5.0.2",
    "es6-promise-plugin": "^4.2.2",
    "highcharts": "^7.1.1",
    "insight": "^0.11.1",
    "ion2-calendar": "^2.2.0",
    "ionic-angular": "^3.9.10-202005061940",
    "ionic-selectable": "^3.4.0",
    "ionicons": "3.0.0",
    "moment": "^2.29.0",
    "ng2-currency-mask": "^4.4.1",
    "npm": "^6.1.0",
    "pdfmake": "^0.1.54",
    "rxjs": "5.5.2",
    "sw-toolbox": "3.6.0",
    "typescript": "^3.6.3",
    "zone.js": "0.8.18"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.2"
  },
  "description": "Potencializando a pecuaria leiteira",
  "cordova": {
    "plugins": {
      "cordova-plugin-statusbar": {},
      "cordova-plugin-file": {},
      "cordova-plugin-geolocation": {},
      "cordova-plugin-network-information": {},
      "cordova-plugin-app-version": {},
      "cordova-plugin-camera": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-speechrecognition": {},
      "cordova-plugin-tts": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-file-opener2": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-market": {},
      "cordova-plugin-background-mode": {},
      "cordova-plugin-androidx-adapter": {},
      "cordova.plugins.diagnostic": {
        "ANDROID_SUPPORT_VERSION": "28.+"
      },
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-inappbrowser": {},
      "cordova-sqlite-storage": {},
      "cordova-plugin-x-socialsharing": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-purchase": {},
      "cordova-plugin-fcm-with-dependecy-updated": {
        "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher",
        "ANDROID_FCM_VERSION": "21.0.0",
        "ANDROID_FIREBASE_BOM_VERSION": "26.0.0",
        "ANDROID_GOOGLE_SERVICES_VERSION": "4.3.4",
        "ANDROID_GRADLE_TOOLS_VERSION": "4.1.0"
      },
      "cordova-plugin-local-notification-12": {}
    },

Platform: Android

OS version: Windows 10 21H2 - 19044.2251 Android 10

Device manufacturer / model: Xiaomi A2 Global

Cordova version (cordova -v): 11.0.0

Cordova platform version (cordova platform ls): Installed platforms: android 9.1.0
Available platforms: browser ^6.0.0
electron ^3.0.0
windows ^7.0.0

Plugin config sorry I did not understand. I am available to send the missing data

let = {
    "to": "/topics/usuario29871",
    "name": "notification",
    "topic": "topico158632-2022-12-14",
    "notification": {
        "body": "Voc\u00ea esta gostando app?. Avalie Agora mesmo!!. Estamos ansiosos pela sua opini\u00e3o",
        "title": "Chegou a hora!...",
        "click_action": "FCM_PLUGIN_ACTIVITY",
        "icon": "smallicon"
    },
    "android": {
        "priority": "high",
        "ttl": "3600s",
        "icon": "smallicon",
        "notification": {
            "channel_id": "fcm_default_channel",
            "sound": "default",
            "color": "#4290b7",
            "icon": "smallicon"
        }
    },
    "apns": {
        "payload": {
            "aps": {
                "badge": 1,
                "sound": "default"
            }
        }
    },
    "data": {
        "mensagem": "",
        "title": "Chegou a hora!...",
        "pagina_notificacao_app": "PainelAtividadesPage", /* This is a page to Open */
        "id_mensagem_tipo": "20",
        "is_exibir_alerta_pagina": false
    }
}

    await cordova.plugins.notification.local.schedule(cordovaNotificacaoOpcoes);
    await this.utilUteis.aguardarUmTempo(200);

    this.adicionarEventoCliqueNotificacao();

private adicionarEventoCliqueNotificacao(): void {
        cordova.plugins.notification.local.un("click", this.programarCliqueNotificacao, this);
        cordova.plugins.notification.local.on("click", this.programarCliqueNotificacao, this);
        }

private programarCliqueNotificacao(notification: any): void {
    this.abrirPaginaInicialNotificacao(notification.id, notification.data);
}

public async abrirPaginaInicialNotificacao(idNotificacao: number, dadosNotificacao: any): Promise<void> {
    console.log(idNotificacao)

    let notificacao: Notification | any;
    let isTecnico = await this.usuarioUteis.isTecnico();

    console.log(notificacao);

    if (!this.usuarioUteis.isLogado()) {
        this.usuarioUteis.sair();
        return;
    }

    if (dadosNotificacao.is_notificacao_offline) {
        notificacao = await this.obterPorId<Notification>(true, idNotificacao);
    } else {
        notificacao = dadosNotificacao;
    }

    if (dadosNotificacao.is_exibir_alerta_pagina === 'false') {
        notificacao.isExibirAlertaPagina = false;
    } else {
        notificacao.isExibirAlertaPagina = true;
    }

    if (
        !this.utilUteis.isNullOuUndefined(notificacao.pagina_notificacao_app) &&
        notificacao.pagina_notificacao_app != ""
    ) {
        if (notificacao.pagina_notificacao_app === "PaginaInicial") {
            await this.moduloUteis.abrirPaginaInicial(isTecnico, notificacao);
        } else {
            this.navegacaoUteis.abrirPagina(notificacao.pagina_notificacao_app, notificacao);
        }
    } else {
        this.navegacaoUteis.abrirPagina("PainelAtividadesPage", notificacao);
    }
}

*Ionic Version (if using Ionic) 5.4.16

Expected Behavior

I believe that when clicking on the app, regardless of whether the app is closed, closed, or open, the app should open on the configured page

Actual Behavior

When clicking on push/notification with the app open, the app closes and does not open on the configured page, being necessary to open it manually.

Steps to Reproduce

01) use Android 10 or lower 02) use the code mentioned above, if the code is the problem, I am at your disposal

Context

What were you trying to do?

Debug logs

Include iOS / Android logs

ios XCode logs Android: $ adb logcat

The adb logcat log got too big, so it's in the link below. I can't follow the debug completely, because when the app closes, it interrupts the debug

VndrGrhrd commented 1 year ago

link do logCAT : (https://github.com/VndrGrhrd/logcat/blob/main/logcat.txt) https://github.com/VndrGrhrd/logcat/blob/main/logcat.txt

VndrGrhrd commented 1 year ago

Forgive me, this is my first app.

One thing I noticed is that when I added a tag <preference name="AndroidLaunchMode" value="singleInstance"/> in the local build, in debug, the problem no longer occurred, but when installing through Google Play the problem remained

App link on GooglePlay if you want to test => https://play.google.com/store/apps/details?id=com.maisl.maisleite

bhandaribhumin commented 1 year ago

Hi @VndrGrhrd thank you for reporting this issue let me check and get back to you shortly.

Maran1994 commented 1 year ago

Hi @bhandaribhumin on clicking the notification status bar the app got destroyed. Please guide me to fix this behavior. I paste the log for reference. This is the log after clicking the notification status bar.

D/CordovaWebViewImpl: >>> loadUrl(javascript:cordova.plugins.notification.local.fireEvent("click",{"id":101,"title":"My Notification","text":"0 minutes and 12 seconds","foreground":true,"ongoing":true,"sticky":true,"autoClear":false,"actions":[],"alarmVolume":-1,"attachments":[],"autoLaunch":false,"clock":true,"defaults":0,"groupSummary":false,"launch":true,"led":true,"lockscreen":true,"number":0,"priority":1,"progressBar":{"enabled":false,"value":0,"maxValue":100,"indeterminate":false},"resetDelay":5,"silent":false,"smallIcon":"res:\/\/icon","timeoutAfter":null,"trigger":{"type":"calendar"},"vibrate":false,"wakeup":true,"fullScreenIntent":false,"triggerInApp":false,"meta":{"plugin":"cordova-plugin-local-notification-12","version":"0.9-beta.5"},"sound":false},{"event":"click","foreground":true,"queued":false,"notification":101})) W/Parcel: Expecting binder but got null! I/CordovaLog: Changing log level to DEBUG(3) I/CordovaActivity: Apache Cordova native platform version 11.0.0 is starting D/CordovaActivity: CordovaActivity.onCreate() D/SystemWebViewEngine: CordovaWebView is running on device made by: Google I/va.hellocordova: Background young concurrent copying GC freed 23916(1476KB) AllocSpace objects, 32(1664KB) LOS objects, 45% free, 3767KB/6898KB, paused 10.787ms,110us total 122.294ms D/PluginManager: init() D/PluginManager: getPlugin - put: CordovaAllowListPlugin D/CordovaSplashScreenPlugin: Auto Hide: true D/CordovaSplashScreenPlugin: Fade: true D/CordovaSplashScreenPlugin: Fade Duration: 500ms D/PluginManager: getPlugin - put: CordovaSplashScreenPlugin D/PluginManager: startupPlugins: put - Device D/PluginManager: startupPlugins: put - LocalNotification D/PluginManager: startupPlugins: put - Permissions D/PluginManager: startupPlugins: put - Badge D/PluginManager: startupPlugins: put - ForegroundPlugin D/PluginManager: startupPlugins: put - CoreAndroid D/PluginManager: postMessage: setupSplashScreen D/CordovaWebViewImpl: >>> loadUrl(https://localhost/index.html) D/CordovaActivity: Started the activity. D/CordovaActivity: Resumed the activity. I/chromium: [INFO:CONSOLE(1)] "Unhandled Promise rejection: NG04002 ; Zone: ; Task: Promise.then ; Value: Error: NG04002 Error: NG04002 at FN.noMatchError (https://localhost/main.c711751a050f9b5a.js:1:139272)