FCM Push Guide
FCM Push Overview
Since Android 8.0, system permissions have been tightened and the lifecycle of third-party push channels has become more limited. This is why we have introduced our FCM push solution. It guarantees push delivery rate on mainstream Android systems.
In the FCM push solution, the channel used for message delivery is no longer the long WebSocket connection that we maintain ourselves, but the communication is done through FCM. A push message is sent in the following way:
- The developer calls the push API to request a push to all or specific devices;
- The cloud push server forwards the request to the FCM;
- The FCM sends the push message through the system channel to the mobile phone, while the system message receiver on the mobile phone displays the push message in the notification bar;
- The end user clicks on the message and the target application or page is launched.
The whole process is similar to Apple's APNs push, and the SDK is basically not called on the client side.
The Android FCM push feature is only available for apps with Business Plans. If you would like to use this feature, please go to Developer Center > Your game > Game Services > Cloud Services > Push Notification > Settings > FCM and enable FCM Push.
Note that FCM push can be turned on and off at any time. If this option is turned off, the next Android push will automatically be sent to the client through our own channel, just like a normal push, with no effect other than the above mentioned issue of our own channel being limited on some ROMs. If this option is enabled again, the push channels of the vendors will be used again.
When FCM push is enabled, a registrationId field is added to each device record in the Installation table to record the vendor-assigned registration ID (similar to the device token in APNs), and a vendor field is added (if this field does not exist, there is a client integration problem) with a value of fcm.
Displaying Badges or Push Notifications
A badge appears on the application icon when there are new notifications.
Notification Bar Messages and Pass-Through Messages
FCM supports pass-through messages to applications when the application is in the foreground.
Offline Push for Instant Messaging
In the Instant Messaging service, offline pushing is available on iOS when the user goes offline. For Android users, there is no offline pushing when using the private channel because chat and push share the same long WebSocket connection, and if the user goes offline in the Instant Messaging service, pushing is necessarily unreachable. However, if FCM push is enabled, Android users have an offline push notification path because the push message goes through FCM, which is essentially the same as on iOS. This means that when FCM push is enabled, the offline push and mute mechanisms in Instant Messaging are also available to Android users who use FCM push.
Limitations
Push message length limit:
- Messages support a maximum of 128 bytes for the application package name and 4KB for the message content.
Minimum Android version requirement:
- FCM push supports Android 4.1 or higher (minSdkVersion: 16).
Description of factors that affect delivery rates:
- Whether the device is online or not. If the device is offline, the push service will cache messages and push them to the device when it is online.
- Whether the application that integrates the Push Notification SDK is uninstalled on the mobile device.
- Whether the network status of the mobile device is stable.
- The security control policy of the mobile device.
- The delivery of transmissions is affected by the Android system and whether the application is running in the background.
Integration
FCM push is essentially dependent on the FCM SDK and server-side capabilities. Our client SDK is a wrapper around the FCM SDK and the actual push requests are passed through LeanCloud to the FCM backend. Our client-side SDK may not be able to keep up with the iteration speed of the FCM, so we recommend that you interface directly with the FCM SDK and store the FCM-assigned "registration id" and FCM identifier (see vendor in previous chapter) in the device information table (Installation) so that you can then use our push API to correctly send push messages to all devices. This will allow us to send correct push messages to all devices via our push API.
Integration on the Client Side
The developer inherits their implementation class from FirebaseMessagingService and then calls the code in the onNewToken callback function to save it as in the example above (remember to replace vendor with fcm). See LCFirebaseMessagingService for sample code.