question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Notification doesn't fire App is in foreground android ?

See original GitHub issue

Hi,

I have integrate remote notification in my react native app. When App is killed and background the notification is coming on notification center and working fine, but when app is in foreground there is nothing happen. No one method is called,

I have do the below code for notification. The issue is only in android, iOS working fine.

Code :

export function setupPushNotification(handleNotification) {
  PushNotification.configure({
    // (optional) Called when Token is generated (iOS and Android)
    // smallIcon: "ic_notification",
    onRegister: function (token) {
      console.log('TOKEN:', token.token);
      AsyncStorage.setItem('deviceToken', token.token);
      //setStoredData('deviceToken', token.token)
      PushNotification.popInitialNotification((notification) => {
        if (notification) {
          console.log('** NOTIFICATION:', notification);
          handleNotification(notification);
        }
      });
    },
    // (required) Called when a remote or local notification is opened or received
    onNotification: function (notification) {

      console.log('** NOTIFICATION: **', notification);

      if (Platform.OS === 'ios') {
        if (notification.alert.length !== 0) {
          handleNotification(notification)
          notification.finish(PushNotificationIOS.FetchResult.NoData);
        }
      } else {
        handleNotification(notification)
      }

    },
    // ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications) 
    senderID: "303349031154",
    // IOS ONLY (optional): default: all - Permissions to register.
    permissions: {
      alert: true,
      badge: true,
      sound: true
    },
    popInitialNotification: false,
    requestPermissions: true,
  });

  return PushNotification
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:7

github_iconTop GitHub Comments

2reactions
tmaly1980commented, May 7, 2019

I just resolved this by fixing the AndroidManifest.xml to what’s in the README. I was migrating from GCM to FCM and missed a few lines:

        <service      android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
                android:exported="false" >
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

For you it could be any number of things, but I’d make sure to go through both the README and configuring Firebase Cloud Messaging: https://firebase.google.com/docs/cloud-messaging/android/client

0reactions
github-actions[bot]commented, May 30, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Notification Doesn't work in the foreground - Stack Overflow
1 Answer 1 ... FCM has different behaviours for app status (foreground and background / killed). You should handle this by the payload...
Read more >
Event 'push-notification' doesn't fire when app is in foreground
I have a standard implementation of listening to event and show a popup with notification contents. Expected behavior: When app is in ......
Read more >
Foreground services - Android Developers
Foreground services perform operations that are noticeable to the user. Foreground services show a status bar notification, so that users are actively aware ......
Read more >
Push notification doesn't open specific screen when app is ...
I have a problem where I need to redirect user to specific post when he taps on notification, but that only works when...
Read more >
Notifications Not Shown - Mobile Push
Android Settings App > Notifications > Your App you should see "Show notifications" enable and all categories underneath enabled. If you have a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found