react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

Notification received but onNotificationOpened and getInitialNotification not fired in release mode when notification clicked in notification tray. Android

Open Zain995 opened this issue 8 years ago • 31 comments

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:

Zain995 avatar Jul 23 '18 13:07 Zain995

+1

gbenga504 avatar Aug 08 '18 04:08 gbenga504

Same issue here. getInitialNotification is not firing for Android

rheng001 avatar Aug 14 '18 16:08 rheng001

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 avatar Aug 14 '18 20:08 esprehn

@esprehn

Tried adding that, still facing the same issue unfortunately. getInitialNotification returns null

rheng001 avatar Aug 15 '18 00:08 rheng001

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

laukaichung avatar Aug 18 '18 08:08 laukaichung

Having the same issue where on android

matdehaast avatar Aug 25 '18 12:08 matdehaast

@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')

tuvshinbatgeru avatar Aug 27 '18 08:08 tuvshinbatgeru

same issue, any ideas? @everyboy

cx5168 avatar Sep 07 '18 06:09 cx5168

same issue ((

aaalive avatar Sep 09 '18 12:09 aaalive

Same issue on android.

juanpaie avatar Sep 14 '18 06:09 juanpaie

If anyone could help take a look into this one on the native side we'd be more than grateful!

Ehesp avatar Sep 14 '18 07:09 Ehesp

any update on this? this is important

damathryx avatar Sep 20 '18 04:09 damathryx

I'd like to help on this issue. How can I help?

krystofbe avatar Sep 21 '18 07:09 krystofbe

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

gbenga504 avatar Oct 09 '18 13:10 gbenga504

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 ?

diego-caceres avatar Oct 12 '18 14:10 diego-caceres

Somebody has a solution?

guitar9 avatar Oct 14 '18 22:10 guitar9

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 avatar Oct 23 '18 12:10 Salakar

@Salakar seems like #1149 is specific to iOS?

thandunaresh avatar Nov 06 '18 16:11 thandunaresh

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

SpaghettiC0des avatar Nov 07 '18 05:11 SpaghettiC0des

Any updates on this?

sangupandi avatar Nov 08 '18 12:11 sangupandi