React-native-push-notification: onNotification never called

Created on 26 Aug 2018  路  2Comments  路  Source: zo0r/react-native-push-notification

Notifications are displayed on my phone when I send them through the "legacy" API (https://fcm.googleapis.com/fcm/send), but onNotification is never called. I receive a token, I send the messages successfully, they are displayed on my phone, but the handler is never called.

Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest
  package="host.exp.exponent"
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools">

  <permission
    android:name="com.eesoft.cardlife.permission.C2D_MESSAGE"
    android:protectionLevel="signature"/>

  <!-- These are required permissions to make the app run -->
  <uses-permission android:name="com.eesoft.cardlife.permission.C2D_MESSAGE" />
  <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
  <uses-permission android:name="android.permission.WAKE_LOCK" />

  <!-- ADD PERMISSIONS HERE -->
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

  <!-- BEGIN OPTIONAL PERMISSIONS -->
  <uses-permission android:name="android.permission.VIBRATE" />
  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

  <!-- These require runtime permissions on M -->
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.CAMERA" />
  <!-- END OPTIONAL PERMISSIONS -->

  <!-- ADD TEST PERMISSIONS HERE -->

  <uses-feature android:glEsVersion="0x00020000" android:required="false" />

  <application
    android:name=".MainApplication"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true">

    <!-- Enables the Google Pay API -->
    <meta-data
        android:name="com.google.android.gms.wallet.api.enabled"
        android:value="true" />

    <activity
      android:name=".LauncherActivity"
      android:exported="true"
      android:launchMode="singleTask"
      android:screenOrientation="portrait"
      android:theme="@android:style/Theme.Translucent.NoTitleBar">
      <intent-filter>
        <data android:scheme="expcd865cdc55864e9a8cbc64fbff02fb86"/>

        <action android:name="android.intent.action.VIEW"/>

        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
      </intent-filter>
    </activity>

    <activity
      android:name=".experience.ExperienceActivity"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
      android:theme="@style/Theme.Exponent.Light"
      android:windowSoftInputMode="adjustResize">
    </activity>

    <activity
      android:name=".MainActivity"
      android:launchMode="singleTask"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
      android:theme="@style/Theme.Exponent.Splash"
      android:windowSoftInputMode="adjustResize">
      <!-- ADD DETACH SCHEME HERE -->
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>

        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
    </activity>

    <activity
      android:name=".experience.ShellAppActivity"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
      android:theme="@style/Theme.Exponent.Splash"
      android:windowSoftInputMode="adjustResize">
      <!-- ADD SHELL INTENT FILTERS HERE -->
    </activity>

    <activity
      android:name=".experience.HomeActivity"
      android:label="@string/app_name"
      android:launchMode="singleTask"
      android:screenOrientation="portrait"
      android:theme="@style/Theme.Exponent.Light">
    </activity>

    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
    <!-- ADD DEV SETTINGS HERE -->
    <activity android:name="abi27_0_0.com.facebook.react.devsupport.DevSettingsActivity"/>
    <activity android:name="abi26_0_0.com.facebook.react.devsupport.DevSettingsActivity"/>
    <activity android:name="abi25_0_0.com.facebook.react.devsupport.DevSettingsActivity"/>
    <activity android:name="abi24_0_0.com.facebook.react.devsupport.DevSettingsActivity"/>
    <activity android:name="abi23_0_0.com.facebook.react.devsupport.DevSettingsActivity"/>
    <activity android:name="abi22_0_0.com.facebook.react.devsupport.DevSettingsActivity"/>
    <activity android:name="abi21_0_0.com.facebook.react.devsupport.DevSettingsActivity"/>

    <activity
      android:name=".ExponentDevActivity"
      android:exported="true"
      android:label="@string/dev_activity_name"
      android:screenOrientation="portrait"
      android:theme="@style/Theme.Exponent.Dark"
      android:windowSoftInputMode="adjustPan">
    </activity>

    <activity
      android:name=".oauth.OAuthWebViewActivity"
      android:screenOrientation="portrait"
      android:theme="@style/Theme.Exponent.Light">
    </activity>

    <activity
        android:name="net.openid.appauth.RedirectUriReceiverActivity"
        tools:node="replace">
      <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="com.eesoft.cardlife" android:path="oauthredirect"/>
      </intent-filter>
    </activity>

    <activity
      android:name=".oauth.OAuthResultActivity">
    </activity>

    <activity
      android:name=".chrometabs.ChromeTabsManagerActivity">
    </activity>

    <activity
      android:name=".experience.ErrorActivity"
      android:theme="@style/Theme.Exponent.Dark"
      android:screenOrientation="portrait">
    </activity>

    <activity
      android:name=".experience.InfoActivity"
      android:screenOrientation="portrait"
      android:theme="@style/Theme.Exponent.Light">
    </activity>

    <activity
      android:name="com.facebook.FacebookActivity"
      android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
      android:label="@string/app_name"
      android:theme="@android:style/Theme.Translucent.NoTitleBar"
      tools:replace="android:theme" />

    <activity
      android:name="com.facebook.ads.InterstitialAdActivity"
      android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
      android:label="@string/app_name"
      android:theme="@android:style/Theme.Translucent.NoTitleBar" />

    <service
      android:name=".ExponentIntentService"
      android:exported="false" />

    <!-- Analytics -->
    <receiver
      android:name="host.exp.exponent.referrer.InstallReferrerReceiver"
      android:exported="true">
      <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />
      </intent-filter>
    </receiver>

    <!--
    This crashes: https://code.google.com/p/analytics-issues/issues/detail?id=667
    TODO: turn it back on when it's fixed
    <service
      android:name="com.google.android.gms.analytics.CampaignTrackingService"
      android:enabled="true"
      android:exported="false" />-->

    <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
              android:enabled="true">
      <intent-filter>
        <action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
      </intent-filter>
    </receiver>

    <service android:name="com.google.android.gms.analytics.AnalyticsService"
             android:enabled="true"
             android:exported="false"/>

    <!-- GCM -->
    <receiver
      android:name="com.google.android.gms.gcm.GcmReceiver"
      android:exported="true"
      android:permission="com.google.android.c2dm.permission.SEND">
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION"/>

        <category android:name="com.eesoft.cardlife"/>
      </intent-filter>
    </receiver>

    <service
      android:name=".gcm.ExponentGcmListenerService"
      android:exported="false">
      <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
      </intent-filter>
    </service>
    <service
      android:name=".gcm.ExponentInstanceIDListenerService"
      android:exported="false">
      <intent-filter>
        <action android:name="com.google.android.gms.iid.InstanceID"/>
      </intent-filter>
    </service>
    <service
      android:name=".gcm.GcmRegistrationIntentService"
      android:exported="false">
    </service>

    <!-- ADD FCM CONFIG HERE -->
    <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.android.c2dm.intent.RECEIVE" />
      </intent-filter>
    </service>

    <!-- ADD FABRIC CONFIG HERE -->
    <!-- BEGIN FABRIC CONFIG -->
    <meta-data
      android:name="io.fabric.ApiKey"
      android:value="a25fafe9f9edee11a9882b32e0cd7a26df6e2c42"/>
    <!-- END FABRIC CONFIG -->

    <!-- ADD GOOGLE MAPS CONFIG HERE -->
    <!-- BEGIN GOOGLE MAPS CONFIG -->
    <meta-data
      android:name="com.google.android.geo.API_KEY"
      android:value="AIzaSyCPyKmt6in3JwAsogYikNNjor8qgU9stRQ"/>
    <!-- END GOOGLE MAPS CONFIG -->

    <!-- ADD BRANCH CONFIG HERE -->

    <!-- The Facebook SDK runs FacebookInitProvider on startup and crashes if there isn't an ID here -->
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="fb0"/>

    <meta-data
        tools:node="replace"
        android:name="android.support.VERSION"
        android:value="26.1.0"
    />
  </application>

</manifest>

Most helpful comment

It looks like I was just missing this line in the intent filters: <action android:name="com.google.firebase.MESSAGING_EVENT" />

All 2 comments

It looks like I was just missing this line in the intent filters: <action android:name="com.google.firebase.MESSAGING_EVENT" />

@KthProg That did it for me (to be more precise, I followed the README to know where to put that). I was migrating from GCM to FCM and missed the manifest changes.

Was this page helpful?
0 / 5 - 0 ratings