Notification received but onNotificationOpened and getInitialNotification not fired in release mode when notification clicked in notification tray. Android
Hi everyone, I am able to receive notification in IOS and android and in IOS onNotificationOpened and getInitialNotification is triggered when i receive notification from server but on android onNotificationOpened and getInitialNotification is not triggered so i am not able to redirect to another page based on data received in notification. I have searched a lot and looked every issue related to Notifications in react-native-firebase issues but no help.
This is android/app .gradle file dependencies dependencies { implementation(project(':react-native-firebase')) { transitive = false } implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') { transitive = true } implementation "com.google.android.gms:play-services-base:15.0.0" implementation "com.google.firebase:firebase-database:16.0.1" implementation "com.google.firebase:firebase-analytics:15.0.2" implementation "com.google.firebase:firebase-functions:15.0.0" implementation "com.google.firebase:firebase-messaging:15.0.2" implementation 'me.leolin:ShortcutBadger:1.1.21@aar' implementation "com.google.firebase:firebase-core:15.0.2" implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.android.support:appcompat-v7:23.0.1" implementation "com.facebook.react:react-native:+" // From node_modules implementation project(':react-native-navigation') }
This is the code i am using to get data from server which is working perfectly on IOS but not on android.
async componentDidMount(){
this.notificationOpenedListener =
firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) => {
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification: Notification = notificationOpen.notification;
console.log(notification);
});
const notificationOpen: NotificationOpen = await
firebase.notifications().getInitialNotification();
if (notificationOpen) {
// App was opened by a notification
// Get the action triggered by the notification being opened
const action = notificationOpen.action;
// Get information about the notification that was opened
const notification: Notification = notificationOpen.notification;
console.log(notification);
}
}
-
Application Target Platform: Android
-
Development Operating System: macOS Sierra
-
Build Tools: compileSdkVersion 25 buildToolsVersion "25.0.1" targetSdkVersion 22
-
React Nativeversion: 0.55.4 -
React Native FirebaseVersion: 4.2.0 -
FirebaseModule: Messaging (firebase-messaging:15.0.2) -
Are you using
typescript? No
Loving react-native-firebase? Please consider supporting them with any of the below:
- 👉 Back financially via Open Collective
- 👉 Follow
React Native FirebaseandInvertaseon Twitter - 👉 Star this repo on GitHub ⭐️
+1
Same issue here. getInitialNotification is not firing for Android
You probably need to add:
@Override
public void onNewIntent(Intent intent) {
setIntent(intent);
super.onNewIntent(intent);
}
to your main activity. This doesn't seem to be in the docs unfortunately.
@esprehn
Tried adding that, still facing the same issue unfortunately. getInitialNotification returns null
There are a lot of people getting problems with the notification click events. The onNotificationOpened is broken on my phone. That suggestion about adding onNewIntent method doesn't work.
https://github.com/invertase/react-native-firebase/issues/1230
Having the same issue where on android
@Zain995 just let me know do you append new RNFirebaseNotificationsPackage() on MainApplication.java ? and it seems to me you have to specify channel id on android as follows notification.android.setChannelId('channelId')
same issue, any ideas? @everyboy
same issue ((
Same issue on android.
If anyone could help take a look into this one on the native side we'd be more than grateful!
any update on this? this is important
I'd like to help on this issue. How can I help?
You might need to send data only messages from firebase to make this work. You cannot do this with the firebase console. Write a custom api request from post man that sends only data only messages to the android devices
I'm also experiencing this in Android, but it is rare, because sometimes the getInitialNotification return null (when opening the app from a push notification), and other it returns the notification correctly, for the same type of notification.
Has anyone found a workaround ?
Somebody has a solution?
Duplicate of #1149 and many others, lets track all onNotificationOpened issues in one place please (same platform or not please discuss on #1149).
Thanks
@Salakar seems like #1149 is specific to iOS?
I'm also experiencing this in Android, but it is rare, because sometimes the
getInitialNotificationreturn null (when opening the app from a push notification), and other it returns the notification correctly, for the same type of notification.
I'm also experiencing the exact issue by @diego-caceres
Any updates on this?