title: react native with push notification run in background
body: <p>I'm trying to implement push notifications with react native with this plugin 
  <a href="https://github.com/zo0r/react-native-push-notification" rel="noreferrer">react-native-push-notifications</a>.
  what I succeed is to get notification when app is running(in foreground), but what I'm looking to do is to get notification when app is closed(background), not running and when I get notification to go into the app.</p>
  
  <p>my code</p>
  
  <pre><code> componentDidMount() {
      this.initEventPushNotification()
      this.initPushNotification()
  
  }
  
  
  initEventPushNotification() {
      AppState.addEventListener('change', (state) =&gt; {
          console.log(state)
          if (state === 'background') {
              PushNotification.popInitialNotification((notification) =&gt; {
                  if (notification) {
                      this.onNotification(notification);
                  }
              });
              PushNotification.setApplicationIconBadgeNumber(0);
          }
          if (state === 'active') {
              PushNotification.popInitialNotification((notification) =&gt; {
                  if (notification) {
                      this.onNotification(notification);
                  }
              })
          }
  
  
      });
  
  }
  
  
  
  initPushNotification() {
      console.log('init')
      PushNotification.configure({
  
          // (optional) Called when Token is generated (iOS and Android)
          onRegister: function (token) {
              AppStore.setFCMToken(token.token)
              FirebaseService.setTokenData(token.token)
          },
  
          // (required) Called when a remote or local notification is opened or received
          onNotification: function (notification) {
              if (!notification.userInteraction) {
                  PushNotification.setApplicationIconBadgeNumber(0);
              }
              if (notification) {
                  console.log(notification)
                  PushNotification.localNotification({
                      /* Android Only Properties */
                      id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
                      ticker: "My Notification Ticker", // (optional)
                      autoCancel: true, // (optional) default: true
                      largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
                      smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
                      bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
                      subText: "This is a subText", // (optional) default: none
                      color: "red", // (optional) default: system default
                      vibrate: true, // (optional) default: true
                      vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
                      tag: 'some_tag', // (optional) add tag to message
                      group: "group", // (optional) add group to message
                      ongoing: false, // (optional) set whether this is an "ongoing" notification
  
                      /* iOS only properties */
  
                      message: "My Notification Message", // (required)
                      playSound: false, // (optional) default: true
                      soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
                      number: '10', // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
                      repeatType: 'day', // (Android only) Repeating interval. Could be one of `week`, `day`, `hour`, `minute, `time`. If specified as time, it should be accompanied by one more parameter 'repeatTime` which should the number of milliseconds between each interval
                      actions: '["Yes", "No"]',  // (Android only) See the doc for notification actions to know more
                  });
              }
              // process the notification
  
              // required on iOS only (see fetchCompletionHandler docs: https://facebook.github.io/react-native/docs/pushnotificationios.html)
              // notification.finish(PushNotificationIOS.FetchResult.NoData);
          },
  
          // ANDROID ONLY: GCM Sender ID (optional - not required for local notifications, but is need to receive remote push notifications)
          senderID: "XXXXXXXXXX1", // my sender ID
  
          // IOS ONLY (optional): default: all - Permissions to register.
          permissions: {
              alert: true,
              badge: true,
              sound: true
          },
  
          // Should the initial notification be popped automatically
          // default: true
          popInitialNotification: true,
  
          /**
            * (optional) default: true
            * - Specified if permissions (ios) and token (android and ios) will requested or not,
            * - if not, you must call PushNotificationsHandler.requestPermissions() later
            */
          requestPermissions: true,
      });
  
  
  }
  </code></pre>
  
  <p>I'm using firebase function to send the notification</p>
  
  <pre><code>export const sendNotificationTest = functions.https
  .onRequest(async (req, res) =&gt; {
      try {
          const { token } = req.body;
          let tokens = "coeC4T6tmeU:APA91bGEQs4MRQXq4C09SKpyK2Oxz7gIKS-QdoGGKeCcxQj2CXGpCD7qe763WnFVgQRer81iZGscASVq-QP7_I81xtCM9vfiPitQJ4P6HFSH3QiGQQljiLPBixsVcCtbDNCZX4z4u8n-"
          let payload = {
              data: {
                  body: 'Message body',
                  title: 'Message title',
                  color: "#00ACD4",
                  priority: "high",
                  icon: "ic_notif",
                  show_in_foreground: 'true',
                  channelId:'sqtrivia-channel'
  
              },
              notification: {
                  title: "Alarm",
                  subtitle: "First Alarm",
                  body: "First Alarm",
                  click_action: "com.myapp.MyCategory" // The id of notification category which you defined with FCM.setNotificationCategories
              }
          };
          let options = { priority: "high", contentAvailable: true };
          // Set the message as high priority and have it expire after 24 hours.
  
  
  
          console.log('token', token)
          if(token){
              let d = await admin.messaging().sendToDevice(token, payload, options);
              return res.status(200).send({ success: d })
          }
          return res.status(400).send({ error: 'you should send token' })
  
  
      } catch (e) {
          console.info(e)
          return res.status(400).send({ error: 0 })
  
      }
  })
  </code></pre>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>   &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.moonsite.sqlivetrivia"&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&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-permission android:name="android.permission.CAMERA"/&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  &lt;permission
          android:name="${applicationId}.permission.C2D_MESSAGE"
          android:protectionLevel="signature" /&gt;
      &lt;uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /&gt;
      &lt;application
        android:name=".MainApplication"
        android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher"
        android:allowBackup="false"
        android:theme="@style/AppTheme"&gt;
         &lt;receiver
              android:name="com.google.android.gms.gcm.GcmReceiver"
              android:exported="true"
              android:permission="com.google.android.c2dm.permission.SEND" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
                  &lt;category android:name="${applicationId}" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  
          &lt;receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" /&gt;
          &lt;receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
          &lt;service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/&gt;
          &lt;service
              android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
              android:exported="false" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
              &lt;/intent-filter&gt;
          &lt;/service&gt;
        &lt;!-- &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; --&gt;
          &lt;service android:name="io.invertase.firebase.messaging.RNFirebaseBackgroundMessagingService" /&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;!-- &lt;meta-data
          android:name="com.google.firebase.messaging.default_notification_channel_id"
          android:value="@string/default_notification_channel_id"/&gt; --&gt;
          &lt;!-- &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; --&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="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>as I said before, I succeed to get notification only when app is running when I send with firebase http function.I tested only in android for now.</p>
  
  <p>when I send in background I get success response when I test in postman</p>
  
  <pre><code>{
  "success": {
      "results": [
          {
              "messageId": "0:1526575831372268%a0cec506f9fd7ecd"
          }
      ],
      "canonicalRegistrationTokenCount": 0,
      "failureCount": 0,
      "successCount": 1,
      "multicastId": 8639210245128054000
  }
  </code></pre>
  
  <p>}</p>
  
  <p>but I don't get it in device(in background)</p>