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.

Duplicate notifications are triggering when app is in background with FCM

See original GitHub issue

I am getting duplicate notification (FCM) when app is in background , and only getting single notification when app is in foreground or close, but the problem lies with background state

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <!-- <- Add this line -->
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <permission
        android:name="${applicationId}.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" /> <!-- < Only if you're using GCM or localNotificationSchedule() > -->
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application
      android:name="com.bizfeed.MainApplication"

      android:label="@string/app_name"
      android:icon="@drawable/logos"
      android:roundIcon="@drawable/logos"
      android:allowBackup="false"
        android:usesCleartextTraffic="true"
        tools:ignore="GoogleAppIndexingWarning"
      android:theme="@style/AppTheme">
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
        <activity
            android:name="com.bizfeed.MainActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:exported="true"
            android:launchMode="singleInstance"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustUnspecified">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <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:host="bizzfeed.page.link"
                    android:scheme="https" />
            </intent-filter>
        </activity>
        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

        <meta-data
            android:name="com.dieam.reactnativepushnotification.notification_channel_name"
            android:value="YOUR NOTIFICATION CHANNEL NAME" />
        <meta-data
            android:name="com.dieam.reactnativepushnotification.notification_channel_description"
            android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION" /> <!-- Change the resource name to your App's accent color - or any other color you want -->
        <meta-data
            android:name="com.dieam.reactnativepushnotification.notification_color"
            android:resource="@android:color/white" /> <!-- < Only if you're using GCM or localNotificationSchedule() > -->
        <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" />

                <category android:name="${applicationId}" />
            </intent-filter>
        </receiver> <!-- < Only if you're using GCM or localNotificationSchedule() > -->
        <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>

<!--       Background(Closed) <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService" /> &lt;!&ndash; < Only if you're using GCM or localNotificationSchedule() > &ndash;&gt;-->

<!--        CLOSED-->
        <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>
<!--        CLOSED END-->


        <!-- </ Only if you're using GCM or localNotificationSchedule() > -->
        <!-- < Else > -->
        <service
            android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>

<!--        Foreground-->
<!--        <service android:name="io.invertase.firebase.messaging.ReactNativeFirebaseMessagingService">-->
<!--            <intent-filter>-->
<!--                <action android:name="com.google.firebase.MESSAGING_EVENT" />-->
<!--            </intent-filter>-->
<!--        </service>-->
    </application>

</manifest>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:14

github_iconTop GitHub Comments

1reaction
Dallas62commented, May 20, 2020

This issue should not occured with the latest version, you will need to check the installation process in the README. Many settings in AndroidManifest are not required anymore.

1reaction
davidrenjicommented, Apr 4, 2020

it looks like removing this fix the duplicate notification:

<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" />

        <category android:name="${applicationId}" />
    </intent-filter>
</receiver> <!-- < Only if you're using GCM or localNotificationSchedule() > -->
Read more comments on GitHub >

github_iconTop Results From Across the Web

FCM showing duplicate notification when app is in background
To handle push notifications manually use handleIntent(intent) of FirebaseMessagingService. This method gets called when application is ...
Read more >
Receive messages in an Apple app - Firebase - Google
FCM delivers all messages targeting Apple apps through APNs. To learn more about receiving APNs notifications via UNUserNotificationCenter, see Apple's ...
Read more >
Guide to React Native Push Notifications: How To Create and ...
The trigger is to send a notification at 10:10 am. Once the trigger is created, the method listens to the background event to...
Read more >
Notifications - Expo Documentation
In rare situations a push token may be changed by the push notification service while the app is running. When a token is...
Read more >
Notifications Not Shown - Mobile Push
When an app is in a Force Stopped / Force Killed state most events including FCM messages for push notifications will not be...
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