React-native-firebase: Notification received but onNotificationOpened and getInitialNotification not fired in release mode when notification clicked in notification tray. Android

Created on 23 Jul 2018  路  31Comments  路  Source: invertase/react-native-firebase

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);
    }
}
  1. Application Target Platform:
    Android

  2. Development Operating System:
    macOS Sierra

  3. Build Tools:
    compileSdkVersion 25
    buildToolsVersion "25.0.1"
    targetSdkVersion 22

  4. React Native version:
    0.55.4

  5. React Native Firebase Version:
    4.2.0

  6. Firebase Module:
    Messaging (firebase-messaging:15.0.2)

  7. Are you using typescript?

    No

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

Notifications General Waiting for User Response

Most helpful comment

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.

All 31 comments

+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 getInitialNotification return 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?

same, any update ?

same here :(

same here.

Also having this issue -- looks like no one's figured it out? It works fine on iOS

Same here :((((((((

Be careful if you're sending "a lot" of data with the notification. I removed images (in base64) from the notifications and the issue of being able to open the app by clicking the notification was solved.

    @Override
    public void onNewIntent(Intent intent) {
        setIntent(intent);
        super.onNewIntent(intent);
    }

Gives me an error when building
MainActivity.java:16: error: cannot find symbol public void onNewIntent(Intent intent) { ^ symbol: class Intent location: class MainActivity 1 error

@MrEdinLaw Add this at the top of your MainActivity.java
import android.content.Intent;

Same here ...

Closed issue for maybe 6 months, just saying "same" is not useful in the open source world @uchar - either open a new issue with full details in the issue template or look harder at the solutions and related issues

Note that if you are integrating react-native-splash-screen or anything that uses multiple Activities this will happen. For splash-screen specifically I posted code up that fixes it: https://github.com/crazycodeboy/react-native-splash-screen/issues/289#issuecomment-502406454

If that doesn't fit your case -> new issue, follow template please

It seems that there was a problem with my AndroidManifest.xml or MainApplication.java .
I copied their contents from this link and now it's working fine.

Was this page helpful?
0 / 5 - 0 ratings