phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

on('notification') not called in background on android 8.1 #2708

Open bilisim1995 opened 5 years ago

bilisim1995 commented 5 years ago

Expected Behaviour

foreground -> pushObject.on(‘notification’).subscribe((notification: any) is called

background -> pushObject.on(‘notification’).subscribe((notification: any) is not called, show default notoication

Coldstart always false..

Platform and Version (eg. Android 8.1)

Android 8.1

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

General Mobile GM8

Cordova CLI version and cordova platform version

Ionic:

ionic (Ionic CLI) : 4.1.2 (/usr/local/lib/node_modules/ionic) Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.2.1

Cordova:

cordova (Cordova CLI) : 7.1.0 Cordova Platforms : android 7.1.0 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.1.4, (and 12 other plugins)

System:

Android SDK Tools : 26.1.1 (/home/oguzhan/android-sdk-linux) NodeJS : v8.11.3 (/usr/local/bin/node) npm : 6.5.0 OS : Linux 4.15

Plugin version

cordova plugin version | grep phonegap-plugin-push   # e.g. 2.2.3

Sample Push Data Payload

const payload = {

    notification: {
      title: plaka,
      body: mesaj,
      sound: "res://platform_default"
    },
    data : {
      oda : oda,
      kid : bid,
      "content_available" : "true"
    }

  }

Notification code

pushObject.on('notification').subscribe((notification: any) =>{ console.log(notification);

    if (notification.additionalData.coldstart) {
      console.log("background");

 }

if(notification.additionalData.foreground) {
  console.log("foreground");

}

  });
jcbriones commented 5 years ago

I have the same problem as this.

bilisim1995 commented 5 years ago

couldn't find a solution to the issues

CSobol commented 5 years ago

Similar issues have been opened and closed multiple times.

Sort of solution: The short answer is that due to changes in firebase vs GCM, and policies on what backgrounded apps may and may not do, you must put everything from your payload into the data block, and get rid of the notification block.

Why this doesn't work:

If you use FCM to send to iOS, your iOS notifications will now break.

Real solution:

This plugin must be updated to allow developers to register intents and use the click_action key of the FCM plugin. This is the new and modern way of acting on notification clicks in Android, and the plugin currently does not support it.

jcbriones commented 5 years ago

Similar issues have been opened and closed multiple times.

Sort of solution: The short answer is that due to changes in firebase vs GCM, and policies on what backgrounded apps may and may not do, you must put everything from your payload into the data block, and get rid of the notification block.

Why this doesn't work:

If you use FCM to send to iOS, your iOS notifications will now break.

Real solution:

This plugin must be updated to allow developers to register intents and use the click_action key of the FCM plugin. This is the new and modern way of acting on notification clicks in Android, and the plugin currently does not support it.

I already have this. I fixed the problem for this by setting the fcm version in gradle to 15.0.0 manually.

CSobol commented 5 years ago

The correct fix is for this project to accept #2369.

bilisim1995 commented 5 years ago

I already have this. I fixed the problem for this by setting the fcm version in gradle to 15.0.0 manually.

How did you do this?

bilisim1995 commented 5 years ago

The correct fix is for this project to accept #2369.

I will try this. Thanks for reply

tb-j commented 5 years ago

The correct fix is for this project to accept #2369.

I will try this. Thanks for reply

Does it work in your case?