2

When I send a notification from Google's Firebase Cloud Messaging Notification Composer (In Background) I always receive two notifications. They only differ in the icon they display next to the message.

I tried the solutions here: FCM showing duplicate notification when app is in background

Here's a screenshot of the duplication of notification: The 'Xerox Mobile Client...'

Here's my manifest showing the pertinent Firebase elements:

<service android:name=".MyFirebaseInstanceIDService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
    </intent-filter>
</service>
<service
    android:name=".MyFirebaseMessagingService"
    android:enabled="true"
    android:exported="true">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>

Here's the portion implementing 'FirebaseInstanceIdService'

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG = "";

    @Override
    public void onTokenRefresh() {
        // Get updated InstanceID token.
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        // If you want to send messages to this application instance or
        // manage this apps subscriptions on the server side, send the
        // Instance ID token to your app server.
        /* TODO - FIrebase -- Register token */
//        sendRegistrationToServer(refreshedToken);

    }
}

Here's the portion implementing 'FirebaseMessagingService'

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "";

    public MyFirebaseMessagingService() {
    }

    // Called when notification is received when app is in foreground
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {


        // TODO(developer): Handle FCM messages here.

        Log.d(TAG, "From: " + remoteMessage.getFrom());

        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());

            if (/* Check if data needs to be processed by long running job */ true) {
                // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.
                // TODO: Firebase -- Handle messages
                //scheduleJob();
            } else {
                // Handle message within 10 seconds
                // TODO: Firebase -- Handle messages
                //handleNow();
            }

        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }

        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should be initiated. See sendNotification method below.
    }

    // TODO: Firebase -- Handle onDeletedMessages() -- https://firebase.google.com/docs/cloud-messaging/android/receive?authuser=2
}

These are the only things I've added I believe. I'm just getting started in implementation. I appreciate any help.

KENdi
  • 7,576
  • 2
  • 16
  • 31
Evan Sevy
  • 659
  • 1
  • 13
  • 25

0 Answers0