首页 > 解决方案 > FirebaseMessasingService 从我的服务器获取通知,但如果我使用 FirebaseConsole,则不会调用我的类

问题描述

这就是我在 AndroidManifest 中的内容:

    <service android:name=".MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
    <service android:name="io.smooch.core.service.SmoochService" />
    <service android:name=".MyFirebaseInstanceIDService">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

我正在使用版本:implementation 'com.google.firebase:firebase-messaging:17.0.0'

这就是我的 FirebaseMessagingService 的样子:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

public void onMessageReceived(final RemoteMessage message) {
    Log.i("", "MyFirebaseMessagingService onMessageReceived");
    final Map data = message.getData();
    FcmService.triggerSmoochNotification(data, this);
    final Map bundle = data;
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            Log.i("", "GLOBAL intances  before GCM:" + Realm.getGlobalInstanceCount(PSApplicationClass.Config));
            try {
                String title = getString(R.string.alert_title_warning) + " " + getString(R.string.trips_remaining_free, user.getTrips_left());
                String message = getString(R.string.alert_freemium_upgrade);
                Notification.generateNotificationStandard(MyFirebaseMessagingService.this, title, message, null, null, false, false);
            } catch (Exception e) {
                Utils.appendLog("GCMIntentService onMessageReceived error: " + e.getMessage(), "E", Constants.PUSH_NOTIFICATIONS);
            }
        }
    });

}

}

基本上我在这个函数的 onMessageReceived 处放了一个断点。

如果服务器向我的应用程序发送通知,该服务将收到通知,我可以根据需要进行处理。但。如果我使用 FirebaseConsole -> GROW -> Can Messaging -> 我创建一个新消息并发送它。我的应用会收到通知。但它会在不输入我的 onMessageReceived 方法的情况下“自动”创建。我怎么能强迫它这样做?这是我通过控制台发送的数据: https ://s3.amazonaws.com/uploads.hipchat.com/39260/829560/7Pp0KJIERZ8XVZZ/upload.png

我究竟做错了什么?

编辑:

就像我说的,我收到通知,但通知是自动创建的,而不是通过我的 FirebaseMessaging 服务。

我确实设法改变了这样的图标:

<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/notification_icon" />

但是当我得到它时,我仍然需要运行其他代码,而不仅仅是显示它。我不知道怎么做

标签: androidfirebasenotificationsfirebase-cloud-messagingfirebase-notifications

解决方案


推荐阅读