代码之家  ›  专栏  ›  技术社区  ›  user2983041

未调用Firebase onMessageReceived

  •  10
  • user2983041  · 技术社区  · 9 年前

    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

    -我从java服务器发送消息,消息没有到达。Java server在消息发送时显示OK。

    -之前,我错误地导入了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
    

    :

    I faced a issue while using the older version of FCM i.e 10.2.6 Unknown intent action: com.google.firebase.MESSAGING_EVENT

    2 回复  |  直到 9 年前
        1
  •  19
  •   JacksOnF1re    6 年前

    1.tl;博士

    您从某处发送的消息需要有一个 和 一贯地

    "Notification messages can contain an optional data payload" ,仅当您的应用程序位于前台时,才会将其提交到您的服务中!)

    必须 您的发布活动将收到 ,如果用户单击通知,将打开!数据有效载荷将在意图内!


    2、信息类型:

    1. 通知消息包含一组预定义的用户可见键。通知消息具有可选的 通知有效负载 而且将会是 交付给用户系统托盘。

      • 如果应用程序位于前台,他们将调用 onMessageReceived

      • 如果通知没有可选的数据负载,则会显示通知,并在单击时打开应用程序。

    2. 数据消息仅包含用户定义的自定义键值对。(解释如下)。如果你想要的话

    从文档中:

    客户端应用程序负责处理数据消息。数据消息

    在这里 : Fcm Message Types


    数据负载是一个简单的json条目,另外在负载中 可以有简单的键和值对。

    例子:

      "data": {
            "eventId" : "1",
            "flavors" : "alpha",
            "minFcmVersion" : "3",
            "showFallbackOnLowVersion" : "false"
      }
    

    enter image description here

    从控制台创建的消息始终是通知消息!

    首先,通过控制台将firebase云消息直接发送到您的 设备(使用fcm令牌)并添加具有示例值的简单数据有效负载。

    后端

    使用RESTAPI,您可以发送数据消息,这些消息只包含自定义键值对,并且将始终到达您的服务!

    HTTP protocol data payload

    后端 您可以在网上找到http请求生成器。我喜欢: hurl.it 和

    Post

    https://fcm.googleapis.com/fcm/send

    4.Gradle

    com.google.firebase:firebase-messaging:20.0.0 < ,或更高

    也就是说,当时较低的版本中有一个bug '11.0.4'

    5、链接和良好阅读

    Receive Messages Documentation 作为SOF答案,对消息类型进行了很好的解释: SOF - Answer - Message Types

        2
  •  0
  •   Vinayak B    9 年前

    尝试以下案例

    1. 检查设备中安装的google play服务是否最新。如果不是,尝试 update
    2. 例如,确保java服务器代码的顺序正确

      https://fcm.googleapis.com/fcm/send ") .标题(“授权”,“密钥=您的firebase\u密钥”) .标题(“缓存控制”,“无缓存”) .标题(“邮递员令牌”,“836e187a-c342-ce8a-3a2d-f541a4d8e416”) .asString();

      1. 检查FCMService类中的日志