FirebaseMessagingService #onMessageReceived未被调用

时间:2018-04-20 10:41:02

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

Firebase服务器发送通知,我明白了,但我的MyFirebaseMessagingService的onMessageReceived没有被调用。

这是MyFirebaseMessagingService:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

    private static String id;
    private static PSTrip trip;

    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));
                final Realm realm = Realm.getInstance(PSApplicationClass.Config);
                try {
                    final RealmResults < PSTrip > completed = realm.where(PSTrip.class).equalTo("status", "active").findAll();
                    if (completed != null && completed.size() > 0) {
                        id = new String(completed.get(0).getId());
                        trip = new PSTrip(completed.get(0));
                        realm.executeTransaction(new Realm.Transaction() {
                            @Override
                            public void execute(Realm realm) {
                                completed.deleteAllFromRealm();
                            }
                        });
                    }
                    generateNotificationStandard(MyFirebaseMessagingService.this, data.get("title"), message, null, null, false, false);
                } catch (Exception e) {
                    Utils.appendLog("GCMIntentService onMessageReceived error: " + e.getMessage(), "E", Constants.PUSH_NOTIFICATIONS);
                }
                realm.close();
            }
        });
    }
}

我正在使用此版本的firebase:

  

实施'com.google.firebase:firebase-messaging:12.0.1'

我在我的AndroidManifest中声明了我的FirebaseMessagingService:

<service android:name=".MyFirebaseMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT" />
    </intent-filter>
</service>

以某种方式显示了我的通知,但我的方法没有被调用。我怎样才能这样做,以便通过它接收和处理我的消息?

另外:服务器使用它来发送数据。这可能是问题吗? https://github.com/jazzband/django-push-notifications

编辑:

也尝试过:

 <service android:name="nl.hgrams.passenger.MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

为了给出完整的路径。但仍然没有。

1 个答案:

答案 0 :(得分:0)

该应用的服务器部分正在尝试作为通知消息发送。这就是造成这个问题的原因,在我弄清楚之后,我与后端人员交谈,为了更改代码以使用数据消息,现在它可以正常工作