FCM服务:
public class FCMService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.i(Constants.TAG,"onMessageReceived");
Log.i(Constants.TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(Constants.TAG, "Message data payload: " + remoteMessage.getData());
}
if (remoteMessage.getNotification() != null) {
Log.d(Constants.TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
}
}
应用 Gradle:
compile 'com.google.firebase:firebase-messaging:10.2.6'
清单:
<service android:name="communications.FCMService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
- 我发送消息来自FCM控制台,但消息没有到达。 FCM控制台在消息发送时显示“OK”。 - 我从Java服务器发送消息,但消息没有到达。 Java服务器在消息发送时显示“OK”。 - 为了发送消息,我使用Android设备中生成的令牌。 - 以前,我错误地导入了FCM库,但该错误已经解决。当发生过去的错误时,每次发送消息时,在Android上会发生异常。现在没有收到任何消息。 - 我在Android设备上有互联网连接,并且我通过另一个我过去实现的应用程序从GCM(而不是FCM)接收消息。 - 应用程序在前台运行。 - 一些带有“fcm”过滤器的日志。当我发送消息时,我会得到这个日志。
08-14 12:09:25.640 800-4739/? D/PowerManagerService: acquireWakeLockInternal: lock=862109980, flags=0x1, tag="wake:bidsy.app.bidsy/communications.FCMService", ws=null, uid=10354, pid=24073
08-14 12:09:25.640 800-4739/? D/PowerManagerNotifier: onWakeLockAcquired: flags=1, tag="wake:bidsy.app.bidsy/communications.FCMService", packageName=bidsy.app.bidsy, ownerUid=10354, ownerPid=24073, workSource=null
08-14 12:09:25.683 24073-24073/bidsy.app.bidsy D/ActivityThread: SVC-Creating service: CreateServiceData{token=android.os.BinderProxy@1c269013 className=communications.FCMService packageName=bidsy.app.bidsy intent=null}
08-14 12:09:25.683 24073-24073/bidsy.app.bidsy D/ActivityThread: SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@1c269013 className=communications.FCMService packageName=bidsy.app.bidsy intent=null}
08-14 12:09:25.685 24073-24073/bidsy.app.bidsy D/ActivityThread: SVC-SERVICE_ARGS handled : 0 / ServiceArgsData{token=android.os.BinderProxy@1c269013 startId=1 args=Intent { act=com.google.firebase.MESSAGING_EVENT pkg=bidsy.app.bidsy cmp=bidsy.app.bidsy/communications.FCMService (has extras) }}
08-14 12:09:25.684 24073-24073/bidsy.app.bidsy D/ActivityThread: SVC-Calling onStartCommand: communications.FCMService@3e035250, flags=0, startId=1
08-14 12:09:25.691 800-1592/? D/PowerManagerService: releaseWakeLockInternal: lock=862109980 [wake:bidsy.app.bidsy/communications.FCMService], flags=0x0, total_time=52ms
08-14 12:09:25.691 800-1592/? D/PowerManagerNotifier: onWakeLockReleased: flags=1, tag="wake:bidsy.app.bidsy/communications.FCMService", packageName=bidsy.app.bidsy, ownerUid=10354, ownerPid=24073, workSource=null
08-14 12:09:25.692 24073-24073/bidsy.app.bidsy D/ActivityThread: SVC-Destroying service: communications.FCMService@3e035250
看起来消息已经到达服务,但没有显示。
当然,在日志中我没有使用任何过滤器来检查消息是否到达onMessageReceived。
我在这里找到了一个类似的问题,但没有得到答案,日志相同:
详细查看整个日志后,我发现当我发送消息时,会出现以下Firebase错误:
D / FirebaseMessaging: Unknown intent action: com.google.firebase.MESSAGING_EVENT
我的问题的解决方案在这里:
我在使用旧版本的FCM(即10.2.6)时遇到了问题:未知意图操作:com.google.firebase.MESSAGING_EVENT