Firebase Server发送通知,我收到了通知,但我的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();
}
});
}
}
我正在使用这个版本的火力基地:
实现 '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>
就像在给出完整的路径一样。 但仍然没有。
应用程序的服务器部分尝试作为通知消息发送。这就是导致问题的原因,在我想通了这一点之后,我与后端人员进行了交谈,以便更改代码以使用数据消息,现在它可以工作