Using FCM
In order to use the FCM push notification feature in Kii Cloud, you should get familiar with the following concepts:
For more information, see the Firebase documentation.
Identifying the FCM user
In order to enable the FCM push notification feature, create a project in the Firebase console and get the assigned server key and the sender ID.
FCM manages a user app that uses an FCM feature under an FCM project and identifies such an app by the server key and the sender ID.
Server key
The server key identifies your server application.
Register the server key to Kii Cloud via the developer portal. Kii Cloud requests the FCM server to send push notifications with the registered server key.
Enter the Firebase server key to the GCM Key field in the developer portal. Kii Cloud processes interaction with GCM and FCM in the same way.
Sender ID
The sender ID configured in the mobile app identifies the FCM project.
The sender ID is included in google-services.json which can be downloaded from the Firebase console. Specify the JSON file when you build the mobile app in Android Studio. The Firebase library integrated into the mobile app uses the sender ID to control the mobile app.
The mechanism is the same for mobile apps developed with the Monaca plugin, though we directly specify the sender ID instead of google-service.json when enabling FCM in mobile apps developed with the Monaca plugin.
Receiving push notifications
In order to receive push notifications in your mobile app, build your app with the FCM library and Google Play services.
The reception process for a push notification uses Android services. The mobile app can receive push notifications even it is not in the foreground nor running because the reception process in the FCM library and the reception handler in the main program are implemented with the services.
AndroidManifest.xml defines how a push notification is processed. The FCM library receives a push notification that is eventually passed to a subclass of the FirebaseMessagingService
class. You develop functions necessary for your mobile app in the subclass.
Settings necessary for the FCM library are automatically added to AndroidManifest.xml by the manifest merger of Android Studio when building the mobile app. You do not need to configure AndroidManifest.xml minutely.
The Google Play services are required to use FCM. The services must be installed on the device in addition to the mobile app which includes the library to call the services.
Push notifications sent to the mobile app are in JSON format. You can include custom data defined in the application in addition to the fields defined by FCM.
Sample code for FCM and GCM
Sample code sets for FCM and GCM are available in the following URLs at GitHub:
- GCM: https://github.com/googlesamples/google-services
- FCM: https://github.com/firebase/quickstart-android/tree/master/messaging
The push notification tutorials use modified versions of these samples customized for Kii Cloud for testing. For more information, see the tutorials.
Note that both FCM and GCM samples are distributed by Google under the Apache License 2.0. You can use the samples as a skeleton for your mobile app.