react-native-fcm: Getting Duplicate Notifications (tested on Android)

Hi,

I’m getting duplicate notifications on Android (haven’t tested ios). My code is quite simple since I’m just starting out:

export default class NotificationService {
    static initHandler() {
      FCM.on(FCMEvent.Notification, async (notification) => this._handleNotification(notification));
    }
    static _handleNotification(notification) {
      console.log("Got " + notification.messageId);
    }
}

and in App.js

NotificationService.initHandler();
export const App = StackNavigator({
  Login: {screen: Login}
});

When I push a message from the backend service I get the same alert on the phone multiple times. I also keep getting previous alerts. The backend is not the problem. I checked that the backend is sending each notification once and I have the same app implemented 100% in Kotlin which works perfectly.

I’m fairly certain that I’m not registering multiple handlers since I checked that initHandler() is only called once. I’m very new to RN, am I doing something wrong or is there a known issue?

  • versions: “react-native-fcm”: “^11.0.2” and “react-native”: “0.51.0”,
  • Device: Samsung S8, Android 7.0
  • This happens no matter what the app state is, foreground, background or stopped (cleared from task list).

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 23 (7 by maintainers)

Most upvoted comments

I had to remove <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>

from AndroidManifest.xml

I was getting duplicated notifications because of developing 2 apps with the same package name.
Both the applications were receiving the Notification