invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.54k stars 2.19k forks source link

Android 9 foreground notification onMessage/onNotification does not fire #1455

Closed allanjsx closed 5 years ago

allanjsx commented 5 years ago

Issue

On Android 9 (tested on Google Pixel XL), when the app receives a notification when it's in foreground, onMessage() or onNotification callbacks are not triggered. The same code worked fine on the previous Android version.

Environment

  1. Application Target Platform:

Android 9

  1. Development Operating System:

macOS High Sierra

  1. Build Tools:

Android Studio

  1. React Native version:

0.55.4

  1. React Native Firebase Version:

4.2.0

  1. Firebase Module:

messaging, notification

  1. Are you using typescript?

No


Loving react-native-firebase? Please consider supporting them with any of the below:

allanjsx commented 5 years ago

I manage to fix it by upgrading these packages to the latest versions:

Firebase Core -> com.google.firebase:firebase-core:16.0.3 Cloud Messaging -> com.google.firebase:firebase-messaging:17.3.0

jeremy8883 commented 5 years ago

Unfortunately, updating firebase core and cloud messaging didn't work for me.

When I updated, originally, I got this gradle sync error:

Error:Failed to notify dependency resolution listener.
The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[16.0.2,16.0.2]], but resolves to 16.0.0. Disable the plugin and check your dependencies tree using ./gradlew :app:dependencies.

So updated the node_modules/react-native-firebase/build.gradle to use the latest packages, and that got things compiling.

compileOnly "com.google.android.gms:play-services-base:15.0.1"
  compileOnly "com.google.firebase:firebase-ads:15.0.1"
  compileOnly "com.google.firebase:firebase-auth:16.0.3"
  compileOnly "com.google.firebase:firebase-config:16.0.0"
  compileOnly "com.google.firebase:firebase-core:16.0.3"
  compileOnly "com.google.firebase:firebase-crash:16.2.0"
  compileOnly "com.google.firebase:firebase-database:16.0.2"
  compileOnly "com.google.firebase:firebase-firestore:17.1.0"
  compileOnly "com.google.firebase:firebase-functions:16.1.0"
  compileOnly "com.google.firebase:firebase-invites:16.0.3"
  compileOnly "com.google.firebase:firebase-storage:16.0.2"
  compileOnly "com.google.firebase:firebase-messaging:17.3.2"
  compileOnly "com.google.firebase:firebase-perf:16.1.0"

Not sure if I did something stupid there.

I receive messages fine when the app is in the background or closed. And messages fully work for me on ios, including when the app is open. It's just on android, and if the app is open.

patroldo commented 5 years ago

Hi. I followed your advices to use latest packages. But i still unable to use onMessage(). Also android 9. Android build-tools(SDK v26)

sam9010 commented 4 years ago

i think you must define channel you can use this url https://rnfirebase.io/docs/v5.x.x/notifications/android-channels