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.
Android 9
macOS High Sierra
Android Studio
React Native version:0.55.4
React Native Firebase Version:4.2.0
Firebase Module:messaging, notification
typescript?No
Loving react-native-firebase? Please consider supporting them with any of the below:
React Native Firebase and Invertase on TwitterI 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
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.
Hi. I followed your advices to use latest packages. But i still unable to use onMessage(). Also android 9. Android build-tools(SDK v26)
i think you must define channel
you can use this url
https://rnfirebase.io/docs/v5.x.x/notifications/android-channels
Most helpful comment
Unfortunately, updating firebase core and cloud messaging didn't work for me.
When I updated, originally, I got this gradle sync error:
So updated the
node_modules/react-native-firebase/build.gradleto use the latest packages, and that got things compiling.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.