Overview
The FCM channel is a system-level push channel provided by Google. On mobile phones with the Google service framework, as the background processes are managed loosely, push notifications can be received if application processes are not force stopped. This channel is not supported for clusters in the Chinese mainland.
Directions
Obtaining a key
FCM PUSH supports the following two methods of key configuration. You just need to choose one of them, but the new proposal method using the server private key is recommended.
1. Server private key (recommended)
Register the application at the FireBase official website. Select Firebase Projects > Select a Project App > Settings > Service Account > Firebase Admin SDK, and click Generate a new private key to get the json file containing the Firebase server private key. Then, go to the Tencent Push Notification Service console > Configuration Management > Basic Configuration > FCM Push Channel, select Server Private Key (Recommended), and click Click to Upload to upload the above-mentioned json file.
2. Legacy server key
Register the application at the FireBase official website. Select Firebase Projects > ** Select a Project App** > Settings > Cloud Messaging to get the Server Key of the FCM app push, and enter the key in the Tencent Push Notification Service console > Configuration Management > Basic Configuration > FCM Push Channel.
Configuration
1. Configure the google-services.json
file.
2. Configure gradle to integrate the Google service.
1. Add the following code to the dependencies node in the project-level build.gradle
file:
classpath 'com.google.gms:google-services:4.2.0'
Caution:
IfFCM Register error! java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.qq.xg4all. Make sure to call FirebaseApp.initializeApp(Context) first.
appears for a version earlier than 4.2.0, add YOUR_GOOGLE_APP_ID
in the string.xml
file in the res/values
folder.
2. Add dependencies in the app-level build.gradle
file:
implementation 'com.tencent.tpns:fcm:[VERSION]-release' // For FCM PUSH, [VERSION] is the version number of the current SDK and can be obtained from "SDK for Android".
implementation 'com.google.firebase:firebase-messaging:17.6.0'
// In the app-level gradle file, add the following to the last line of the code and put google-services.json under the root directory of your app model
apply plugin: 'com.google.gms.google-services'
Note:
For FCM PUSH, [VERSION] is the version number of the current SDK and can be obtained from the SDK for Android. Configure google-play-services for Google (v17.0.0+ or later recommended; an earlier version may cause FCM registration failure).
Enabling FCM PUSH
Add the following code before calling the Tencent Push Notification Service registration code XGPushManager.registerPush
:
XGPushConfig.enableOtherPush(this, true);
The log of successful FCM registration is as follows:
V/TPush: [XGPushConfig] isUsedOtherPush:true
I/TPush: [OtherPush] checkDevice pushClassNamecom.tencent.android.tpush.otherpush.fcm.impl.OtherPushImpl
I/TPush: [XGPushManager] other push token is : dSJA5n4fSZ27YeDf2rFg1A:APA91bGiqSPCMZTuyup**********f1fBIahZKYkth2OoDpixDPQmEZkQ11fX06mw_1kEaW5-jFmT4YwlER4qfX66h_BIoUxOyj_tKqZSUg7oHigIKaOrDWmMQfMAqGoT8qSfg other push type: fcm
Code obfuscation
-keep class com.google.firebase.** {*;}
Note:
Obfuscation rules must be stored in the proguard-rules.pro
file at the application project level.
Troubleshooting
Why can't messages pushed through the FCM channel be received?
1. On mobile phones with the Google service framework outside the Chinese mainland, as the background processes are managed loosely, messages pushed through the FCM channel can be received if application processes are not force stopped.
2. The background process management policies of phone brands in the Chinese mainland are generally strict, which also restrict the Google services on the background. On such phones, messages pushed through the FCM channel cannot be sent or received. To receive them, keep the app running on the foreground.
How do I force stop an application process?
Go to Settings > Application Management on the phone, select a specific application, and click Stop, Force Stop, or a similar button to stop the application. For most Chinese phones, closing the application process on the multitasking page can also be considered as force stopping the application process (this is not the case for phones outside the Chinese mainland).
Was this page helpful?