FCM Push Notifications Not Working in Quit State on Android 11 (React Native)

113 views Asked by At

I'm encountering issues with FCM push notifications in my React Native app specifically on Android 11 devices. Notifications work as expected on Android 13, but on Android 11, they only appear when the app is in the foreground or background, not when it's in the quit state.

Here's what I've already tried:

Followed Firebase's official React Native FCM integration guide. Verified notification payload format and structure, including high-priority elements. Double-checked AndroidManifest.xml for necessary permissions and services.

Additional Information:

Firebase SDK version: 18.5.0 React Native version: 0.72.1

How can I ensure FCM push notifications are delivered and displayed even when the app is in the quit state on Android 11 devices?

Android Manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>


    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustPan"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
             <data
      android:scheme="com.locom"
      android:host="oauthredirect" />
        </intent-filter>
      </activity>

      <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground" android:value="false"/>
<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_fcm_notification" />
    
    </application>
</manifest>
1

There are 1 answers

1
Rohit Aggarwal On

There is some problem with your AndroidManifest.xml file. Use

<meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                    android:value="true"/>

If it still does not work. You can simply copy paste this

<meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                    android:resource="@android:color/white"/>
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" android:exported="true" />

    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" android:exported="true" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver" android:exported="true">
      <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.RNPushNotificationListenerServiceGcm"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
    </service>

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

Here android:exported is set to false for all activities. Also you are missing Actions and publisher tags for reciever