每次我从Notification Composer发送时,Firebase云消息传递(FCM)都会给我双重通知 - Android

时间:2018-03-08 18:57:17

标签: firebase push-notification notifications firebase-cloud-messaging

当我从Google的Firebase云消息通知编写器发送通知时(在后台),我总是收到两个通知。它们仅在消息旁边显示的图标上有所不同。

我在这里尝试了解决方案:FCM showing duplicate notification when app is in background

以下是重复通知的屏幕截图: The 'Xerox Mobile Client...'

这是我的清单,显示了相关的Firebase元素:

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

以下是实施“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);

    }
}

以下是实施“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
}

我相信这些是我添加的唯一内容。我刚刚开始实施。我感谢任何帮助。

0 个答案:

没有答案