invertase / notifee

⚛️ A feature rich notifications library for React Native.
https://notifee.app
Apache License 2.0
1.88k stars 228 forks source link

[Android] onBackgroundEvent not triggered #978

Closed one1two2 closed 8 months ago

one1two2 commented 10 months ago

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 commented 10 months ago

same issue

feitan43 commented 10 months ago

same issue

brunoworkl commented 9 months ago

Same issue here

D4uS1 commented 9 months ago

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.

github-actions[bot] commented 8 months ago

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.

IshaanRawat commented 7 months ago

Same Issue.

LuckyMadu commented 6 months ago

Facing the same issue, no support at all. https://github.com/invertase/notifee/issues/1044

shannon77777 commented 5 months ago

Same issue here.

Gautham495 commented 4 months ago

Why is this closed? Issue is happening in android.

truongnv98 commented 4 months ago

Android: For anyone using react native firebase

Roman-ZN commented 3 months ago

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 commented 2 months ago

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?