title: react native firebase push notification when app is closed/swiped from list
body: <p>I'm trying to show push notification when app is closed so I'm setting up the push notification with react-native-firebase with <a href="https://rnfirebase.io/docs/v4.0.x/notifications/android" rel="nofollow noreferrer">this docs</a> </p>
  
  <p>I set AndroidManifest.xml as described in docs</p>
  
  <pre><code>    &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.moonsite.sqlivetrivia"
      android:versionCode="1"
      android:versionName="1.0"&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/&gt;
      &lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
      &lt;uses-permission android:name="android.permission.VIBRATE" /&gt;
  
      &lt;uses-sdk
          android:minSdkVersion="16"
          android:targetSdkVersion="22" /&gt;
  
      &lt;application
        android:name=".MainApplication"
        android:allowBackup="true"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:theme="@style/AppTheme"&gt;
        &lt;receiver android:name="io.invertase.firebase.notifications.RNFirebaseNotificationReceiver"/&gt;
    &lt;receiver android:enabled="true" android:exported="true"  android:name="io.invertase.firebase.notifications.RNFirebaseNotificationsRebootReceiver"&gt;
      &lt;intent-filter&gt;
        &lt;action android:name="android.intent.action.BOOT_COMPLETED"/&gt;
        &lt;action android:name="android.intent.action.QUICKBOOT_POWERON"/&gt;
        &lt;action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/&gt;
        &lt;category android:name="android.intent.category.DEFAULT" /&gt;
      &lt;/intent-filter&gt;
    &lt;/receiver&gt;
    &lt;meta-data
      android:name="com.google.firebase.messaging.default_notification_icon"
      android:resource="@drawable/ic_stat_ic_notification" /&gt;
        &lt;meta-data
      android:name="com.google.firebase.messaging.default_notification_color"
      android:resource="@color/colorAccent" /&gt;
         &lt;!-- 
  
        &lt;meta-data
      android:name="com.google.firebase.messaging.default_notification_channel_id"
      android:value="@string/default_notification_channel_id"/&gt; --&gt;
        &lt;service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService"&gt;
          &lt;intent-filter&gt;
          &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
      &lt;service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService"&gt;
          &lt;intent-filter&gt;
          &lt;action android:name="com.google.firebase.INSTANCE_ID_EVENT"/&gt;
          &lt;/intent-filter&gt;
      &lt;/service&gt;
        &lt;service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" /&gt;
  
        &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name"
          android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
          android:windowSoftInputMode="adjustResize"
          android:launchMode="singleTop"
  
          &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.firebase.MESSAGING_EVENT" /&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;activity android:name="com.facebook.react.devsupport.DevSettingsActivity" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>then I wrote the code in react native</p>
  
  <pre><code>    import React, { Component } from 'react'
  import { View } from 'react-native'
  import { Input, Text, Button } from '../Components'
  import type { RemoteMessage } from 'react-native-firebase'
  import firebase from 'react-native-firebase'
  import type { Notification, NotificationOpen } from 'react-native-firebase';
  
  export default class TestComponent extends Component {
  
    async componentDidMount() {
      await this.SetUpAuth();
      await this.SetUpMessaging();
      this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen: NotificationOpen) =&gt; {
        // Get the action triggered by the notification being opened
        const action = notificationOpen.action;
        // Get information about the notification that was opened
        const notification: Notification = notificationOpen.notification;
      });
      const notificationOpen: NotificationOpen = await firebase.notifications().getInitialNotification();
      if (notificationOpen) {
        console.log(notificationOpen)
        // App was opened by a notification
        // Get the action triggered by the notification being opened
        const action = notificationOpen.action;
        // Get information about the notification that was opened
        const notification: Notification = notificationOpen.notification;
      }
  
  
    }
    componentWillUnmount() {
  
    }
  
  
    async SetUpAuth() {
      const credential = await firebase.auth().signInAnonymouslyAndRetrieveData();
      if (credential) {
        console.log('default app user -&gt;', credential.user.toJSON());
      } else {
        console.error('no credential');
      }
    }
    async SetUpMessaging() {
      this.notification2 = new firebase.notifications.Notification()
        .setNotificationId('notificationId')
        .setTitle('My notification title')
        .setBody('My notification body')
        .android.setChannelId('test')
        .android.setClickAction('action')
        .setData({
          key1: 'value1',
          key2: 'value2',
        });
  
      this.notification2
        .android.setChannelId('channelId')
        .android.setSmallIcon('ic_launcher');
      console.log('assa')
  
      onTokenRefreshListener = firebase.messaging().onTokenRefresh(fcmToken =&gt; {
        console.log('token generated -&gt;', fcmToken);
        //   store.dispatch(DeviceActions.SetFCMToken(fcmToken));
      });
  
      const fcmToken = await firebase.messaging().getToken();
      if (fcmToken) {
        // user has a device token
        console.log('has token -&gt;', fcmToken);
        console.log(firebase.auth().currentUser._user)
        firebase.database().ref(`/users/${firebase.auth().currentUser._user.uid}`).set({ pushToken: fcmToken })
        //   store.dispatch(DeviceActions.SetFCMToken(fcmToken));
      } else {
        // user doesn't have a device token yet
        console.error('no messaging token');
      }
  
      const messagingEnabled = await firebase.messaging().hasPermission();
      if (messagingEnabled) {
        // user has permissions
        console.log('User has FCM permissions');
      } else {
        // user doesn't have permission
        console.log('User does not have FCM permissions');
        await this.RequestMessagePermissions();
      }
  
      messageListener = firebase.messaging().onMessage((message: RemoteMessage) =&gt; {
        console.log(`Recieved message - ${JSON.stringify(message)}`);
      });
  
      notificationDisplayedListener = firebase
        .notifications()
        .onNotificationDisplayed(notification =&gt; {
          // Process your notification as required
          // ANDROID: Remote notifications do not contain the channel ID. You will have to specify this manually if you'd like to re-display the notification.
          console.log(`Recieved notification 1`);
        });
      notificationListener = firebase
        .notifications()
        .onNotification(notification =&gt; {
          console.log(notification)
          firebase.notifications().displayNotification(this.notification2)
          // Process your notification as required
          console.log(`Recieved notification 2`);
        });
    }
  
  
    async RequestMessagePermissions() {
      console.log('request')
      console.log('Requesting FCM permission');
      await firebase
        .messaging()
        .requestPermission()
        .catch(err =&gt; console.err(err));
    }
  
  
    render() {
      return (
        &lt;View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}&gt;
  
        &lt;/View&gt;
      )
    }
  }
  </code></pre>
  
  <p>then I created firebase http function just for test</p>
  
  <pre><code>export const sendNotification = functions.https
  .onRequest(async (req, res) =&gt; {
      try {
          const { token } = req.query;
          let tokens = 'fyTfgNZAUBA:APA91bGnx9Vp9MwRA4ohVKcNOM8d5s4a4TXdtI0KTSzcWEgZX1WoLGpofcVQFTCdSbnbqObkukzJEXF3cbmvENYD5pr2MrukjqUNy_bclDuM3rJsV5iSU1vWywL2ZVijJ3s0E9GNfRRe'
          var payload = {
              notification: {
                title: 'Urgent action needed!',
                body: 'Urgent action is needed to prevent your account from being disabled!',
                sound: 'default',
                  color: '#84B2D9',
                  icon: 'ic_notification',
                  click_action: 'OPEN_MAIN_ACTIVITY'
              }
            };
  
            // Set the message as high priority and have it expire after 24 hours.
            var options = {
              priority: 'high',
              timeToLive: 60 * 60 * 24
            };
  
  
            console.log('token',token)
          let d = await admin.messaging().sendToDevice(tokens, payload,options);
          return res.status(200).send({ success: d})
  
      } catch (e) {
          console.info(e)
          return res.status(400).send({ error: 0 })
  
      }
  </code></pre>
  
  <p>})</p>
  
  <p>in the response from http function I get success(as you can see here)</p>
  
  <pre><code>{
  "success": {
      "results": [
          {
              "messageId": "0:1525112032423298%a0cec506a0cec506"
          }
      ],
      "canonicalRegistrationTokenCount": 0,
      "failureCount": 0,
      "successCount": 1,
      "multicastId": 5934848553304349000
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and in my debugger in console log I get the notification as I want 
  <a href="https://i.stack.imgur.com/05QCS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/05QCS.jpg" alt="enter image description here"></a></p>
  
  <p>but the issue I don't get push notification when app is closed. I want to get any notification when I'm not into the app.</p>
  
  <p>in addition when I use to display the notification when I get any notification</p>
  
  <pre><code>notificationListener = firebase
    .notifications()
    .onNotification(notification =&gt; {
      console.log(notification)
      firebase.notifications().displayNotification(this.notification2)
      // Process your notification as required
      console.log(`Recieved notification 2`);
    });
  </code></pre>
  
  <p>}</p>
  
  <p>so it not display my details here</p>
  
  <pre><code>  this.notification2 = new firebase.notifications.Notification()
    .setNotificationId('notificationId')
    .setTitle('My notification title')
    .setBody('My notification body')
    .android.setChannelId('test')
    .android.setClickAction('action')
    .setData({
      key1: 'value1',
      key2: 'value2',
    });
  </code></pre>
  
  <p>so do i need to save it on state and then in title to display the data? </p>