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.

Cannot get Notification content if app is in background

See original GitHub issue

I can recevie the notification from firebase remotly. If the app is runing in foreground, I receive the notification content normally, but if the app is in background, I receive the notification and when click on notification, the app opens up, but the method: onNotification is not called for some reason. I have seen a lot of issues based on this problem, but no success.

here is my AndroidManifest.xml

`<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/icon" android:allowBackup="false" android:theme="@style/AppTheme">

    <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/icon"/>

    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver>
    <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>

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


  <activity
    android:name=".SplashActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>


  <activity
    android:name=".MainActivity"
    android:theme="@style/SplashTheme"
    android:label="@string/app_name"
    android:launchMode="singleTop"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
    android:windowSoftInputMode="adjustResize"
    android:exported="true">
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>`

and here is my App.js


import PushNotification from 'react-native-push-notification';

    class App extends Component {
      state = { color: 'red' };
      constructor() {
        super();
        PushNotification.configure({
          onRegister: ({ token }) => this.register(token),
          onNotification: notif => this.receivePushNotification(notif),
          senderID: 'XXXX',
          requestPermissions: true
        });
     }

        componentDidMount = () => {
          SplashScreen.hide();
          AppState.addEventListener('change', this.handleAppStateChange);
        };

        handleAppStateChange = appState => {
          if (appState === 'active') {
            PushNotification.popInitialNotification(notification => {
              console.warn('notification', notification); //notification is null
            });
          }
        };

        register = token => {
          console.warn('token', token);
        };

        receivePushNotification = notification => {
          console.warn('notification', notification); //only enter here if I receive the notification in foreground mode, if I receive in background and click on notification, this method is not being called
        };
    }

If anybody knows how to solve this, or know if FCM is supported by this library I would greatly appreciate it.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
uzairkhan01commented, Nov 29, 2018

Thank you @hoangpm2

0reactions
hoangpm2commented, Nov 29, 2018

@uzairkhan01 I am using react-native-firebase. https://rnfirebase.io/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Notifications Not Showing Up? 10 Fixes You Can Try
Not seeing notifications show up on your Android phone? Try these fixes to get Android notifications working again.
Read more >
Issue with receiving notifications when app is in background
For notification messages, onMessageReceived is only called if your app is in the foreground. Otherwise the the message will be delivered to the ......
Read more >
Pushing Background Updates to Your App - Apple Developer
A background notification is a remote notification that doesn't display an alert, play a sound, or badge your app's icon. It wakes your...
Read more >
Notifications Overview | Android Developers
A notification is required when your app is running a "foreground service"—a Service running in the background that's long living and noticeable to...
Read more >
Data & Background Notifications - OneSignal Documentation
. Background/Data Notification Limitations ... If you force close the app, it cannot receive background/data notifications. iOS Apps are force closed when you ......
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