【发布时间】:2018-10-01 01:31:04
【问题描述】:
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'
我的 FirebaseMessagingService 在我的 AndroidManifest 中声明如下:
<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>
提供完整路径。但还是什么都没有。
【问题讨论】:
-
你用什么设备测试通知?
-
当您收到您的应用程序位于前台或后台位置的通知时
-
我使用的是 Nexus 5、乐视 LePro2 和华为 Mate 10 Pro。 PS:如果应用程序在后台或前台,我确实会收到通知。但我收到默认通知。我的 FirebaseMessagingService 没有被调用
-
fcm 发送什么类型的消息。我正在使用数据消息,所以它可以工作。您使用的是数据消息还是通知消息?如果您使用通知消息,我们的 firebase sdk 会处理进程并自动在系统托盘中显示通知
标签: android firebase push-notification firebase-cloud-messaging android-notifications