[英]FirebaseMessagingService #onMessageReceived is not being called
Firebase Server sends notification, I get it, but my MyFirebaseMessagingService's onMessageReceived is not being called. Firebase服务器发送了通知,我知道了,但是未调用MyFirebaseMessagingService的onMessageReceived。
This is MyFirebaseMessagingService: 这是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();
}
});
}
}
I am using this version of firebase: 我正在使用此版本的Firebase:
implementation 'com.google.firebase:firebase-messaging:12.0.1'
实施'com.google.firebase:firebase-messaging:12.0.1'
And I have my FirebaseMessagingService declared in my AndroidManifest like this: 我在AndroidManifest中声明了FirebaseMessagingService,如下所示:
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Somehow my notifications are shown, but my method is not being called. 以某种方式显示我的通知,但未调用我的方法。 How can I make it so my messages are received and handled through this?
如何做到这一点,以便通过此方式接收和处理我的消息?
Also: the server uses this to send the data. 另外:服务器使用它来发送数据。 Might this be the issue?
这可能是问题吗? https://github.com/jazzband/django-push-notifications
https://github.com/jazzband/django-push-notifications
Also tried: 还尝试了:
<service android:name="nl.hgrams.passenger.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
as in to give the full path. 如完整路径。 but still nothing.
但还是一无所有。
The server part of the app was trying to send as Notification Message. 应用程序的服务器部分正在尝试以通知消息的形式发送。 This is what was causing the issue, and after I figured this out, I talked with the backend guy, in order to change the code to use Data Message, and now it works
这就是造成此问题的原因,在我弄清楚这一点之后,我与后端人员进行了交谈,以便将代码更改为使用数据消息,现在它可以了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.