wix / react-native-notifications

React Native Notifications
MIT License
3.22k stars 761 forks source link

completion() doesn't work on Android 12 (API 31) #988

Open mutablestudio opened 1 year ago

mutablestudio commented 1 year ago

I have followed all the Android setup instructions and have FCM setup, google-services.json, etc. registerNotificationReceivedForeground and registerNotificationReceivedBackground events both fire on Android but the completion() call does not show the Notification on Android (works fine on iOS).

"react-native-notifications": "5.0.0" - also tried 4.3.3, 4.3.1... "react-native": "0.68.5",

Samsung Galaxy S10e (api 31) and Pixel 3 devices.

I have to do the following to get a Notification to appear on Android:

   Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion: (response: NotificationCompletion) => void) => {
      if (Platform.OS === 'android') {
        Notifications.postLocalNotification({
          title: "Notification",
          body: "You have a notification!",
          extra: "data"
        })
      } else {
        // Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
        completion({alert: true, sound: true, badge: true});
      }
    });

Am I missing something for the Android setup??

stale[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

mattsoftware commented 10 months ago

I have the same issue. I am not an android developer so I do not understand the ecosystem that well. It feels like I have everything setup correctly as I can send push notifications from AWS and my app does receive the message both when the app is running in the foreground as well as background. (via console.log in the event handlers.) Nothing happens when the app is 'dead'.

In IOS the notification seems to be handled by the operating system and displayed without the app being open or in the background. Does the android app need to do something to display the notification? If the app is dead how is that code going to run?

Any help appreciated.

luca-tomasetti commented 9 months ago

I'm experiencing something similar with version 5.1.0 when I'm trying to handle the notifications in the foreground.

VladislavAnanyev commented 6 months ago

Similar problem