【发布时间】:2018-01-22 03:15:40
【问题描述】:
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());
}
}
}
应用分级:
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>
-我发送消息from FCM console 并没有到达。发送消息时,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
我发现这里没有回答类似的问题,有相同的日志:
Can't receive the push notification message
详细查看整个日志后,我发现当我发送消息时,会发生以下 Firebase 错误:
D / FirebaseMessaging: Unknown intent action: com.google.firebase.MESSAGING_EVENT
我的问题的解决方案在这里:
【问题讨论】:
-
您确定您的授权密钥和设备令牌仍然有效.. 重新安装时设备令牌将更改.. 确保您的 google-services.json 也有效
-
在每次测试中,我都卸载了应用程序并生成了一个新令牌。 Android Firebase 工具告诉我应用已正确链接到项目。
-
您的消息是否有“数据”负载?没有数据负载的消息(例如来自控制台)不会到达 FirebaseMessagingService。
-
我从 FCM 控制台发送消息。消息的文本是强制性的。
-
是的,但是如果您的有效负载没有“数据”部分,则这些消息将不会到达您的 MessagingService,尽管它们会显示出来。
标签: android firebase firebase-cloud-messaging