firebase cloud messaging didn't see xiaomi dev

2020-02-13 04:46发布

问题:

I'm building an react native app. I want to send cloud messages from firebase but i can't. i prepared project and install on my devices. one of them samsung other one is xiaomi. when i send notification i can see on my samsung but not xiaomi. also i can send notification my virtual android device with fcmToken. do you want how can i fix that problem?

firebase cloud messagin console: https://pasteboard.co/IxyD0p3.png

System:

OS: Windows 10

CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz

Memory: 1.46 GB / 7.89 GB

Binaries:

Node: 10.15.3 - C:\Program Files\nodejs\node.EXE

npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

IDEs:

Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842

react-native-cli: 2.0.1

react-native: 0.60.5


app/build gradle dependencies
implementation "com.google.android.gms:play-services-base:16.0.0"
    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
    implementation "com.google.firebase:firebase-core:16.0.9"
    implementation "com.google.firebase:firebase-messaging:19.0.0"
    implementation 'com.google.firebase:firebase-analytics:17.2.0'
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar'

/build gradle
classpath("com.android.tools.build:gradle:3.4.1")
        classpath('com.google.gms:google-services:4.3.2')

回答1:

There are 2 types of FCM notifications: Notification message and Data message.

Notification message looks like:

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    }
  }
}

and triggers method OnMessageReceaved() of FirebaseMessagingService. Many devices (especially Huawei and Xiaomi) try to do everything to kill background services to prevent battery drain. So the FirebaseMessagingService isn't the best way to handle notifications.

Second type is
Data message:

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "data":{
      "Nick" : "Mario",
      "body" : "great match!",
      "Room" : "PortugalVSDenmark"
    }
  }
}

This type is handled by the system tray, so you don't need any of service running to get the notification. Its much more convenient method, but as far i know, it can't be achieved with the console.

You would probably need server API to send Data message.

Read this for more details.