Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] onBackgroundEvent not triggered #978

Closed
one1two2 opened this issue Jan 31, 2024 · 12 comments
Closed

[Android] onBackgroundEvent not triggered #978

one1two2 opened this issue Jan 31, 2024 · 12 comments

Comments

@one1two2
Copy link

one1two2 commented Jan 31, 2024

I created notifee, firebase integration. It works very well with exception on trigger onBackgroundEvent. I want to perceive information when user click notification on background. It only opens an application. iOS works well. Maybe I missing something obvious.

Flows:
Receive in foreground -> open in foreground -> trigger onForegroundEvent (GOOD)
Receive in foreground -> open in background -> trigger onBackgroundEvent (GOOD)
Receive in background -> open in background -> trigger nothing, app opened (NOT GOOD)
Receive in background -> open in foreground -> trigger nothing , app opened(NOT GOOD)

packages

"@notifee/react-native": "^7.8.2"
"react-native": "0.72.10"

index.js

notifee.onForegroundEvent(({ type, detail }) => {
	console.log('foreground')

	switch (type) {
		case EventType.PRESS:
			console.log('User pressed notification', detail.notification);
			break;
	}
});

notifee.onBackgroundEvent(async ({type, detail}) => {
	console.log('background')

	switch (type) {
		case EventType.PRESS:
			console.log('User pressed notification', detail.notification);
			break;
	}
});

async function onMessageReceived(message: any) {
	console.log('message')
	console.log(message.data)
	if (Platform.OS === 'android' && AppState.currentState !== 'active') return

       const {data, notification} = message;

	const channelId = await notifee.createChannel({
		id: data.guid,
		name: data.guid,
	});

	await notifee.displayNotification({
		title: notification.title,
		body: notification.body,
		data: {
			guid: data.guid,
			id: data.id,
			type: data.type
		},
		android: {
			channelId,
			pressAction: {
				id: 'default',
			},
		},
		ios: {
			categoryId: data.type.toString()
		}
	});
}

messaging().onMessage(onMessageReceived);
messaging().setBackgroundMessageHandler(onMessageReceived);

AppRegistry.registerComponent('swpanel', () => App);

Gradle dependencies

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")
    implementation "com.android.installreferrer:installreferrer:2.2"

    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")
    implementation 'com.google.firebase:firebase-analytics:17.4.1'

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }
}
@MinaSamir11
Copy link

same issue

1 similar comment
@feitan43
Copy link

feitan43 commented Feb 5, 2024

same issue

@brunoworkl
Copy link

Same issue here

@D4uS1
Copy link

D4uS1 commented Feb 14, 2024

We are also facing this issue. Since it is also not possible to use the firebase callbacks because of this issue it is impossible to track if the user opened the app by clicking on a notification at the moment.

Copy link

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 28, 2024
@IshaanRawat
Copy link

Same Issue.

@LuckyMadu
Copy link

Facing the same issue, no support at all.
#1044

@shannon77777
Copy link

Same issue here.

@Gautham495
Copy link

Why is this closed? Issue is happening in android.

@truongnv98
Copy link

Android: For anyone using react native firebase

  • background: use the messaging().onNotificationOpenedApp()
  • close app: use the messaging().getInitialNotification()
  • foreground app: use the notifee.onForegroundEvent()

@Roman-ZN
Copy link

Roman-ZN commented Aug 12, 2024

Android: For anyone using react native firebase

  • background: use the messaging().onNotificationOpenedApp()
  • close app: use the messaging().getInitialNotification()
  • foreground app: use the notifee.onForegroundEvent()

@truongnv98 the issue is that notifee.onNotificationOpenedApp method does not work. I'm not sure how it could help to solve problem described above.

@Eclipses-Saros
Copy link

seems like firebase received background event, makes notification. but notifee can't catch because origin context is not theirs. so nothing happened when you press the notification. have you tried create notifee's notification onBackgroundHandler function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests