FCM 通道是谷歌推出的系统级推送通道,在国外具备谷歌 Service 框架的手机上,鉴于其较宽松的后台进程管理方式,在应用进程未被强制停止的情况下,可以收到推送消息。FCM 通道不支持国内集群。
FCM 推送支持两种密钥配置,以下方式二选一,推荐使用“服务器私钥”的新协议方式。
classpath 'com.google.gms:google-services:4.2.0'
注意:如果使用低于4.2.0版本出现
FCM Register error! java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.qq.xg4all. Make sure to call FirebaseApp.initializeApp(Context) first.
,建议在 res/values 文件夹下的 string.xml, 加上 YOUR_GOOGLE_APP_ID。
在应用级的 build.gradle 文件中,添加依赖:
implementation 'com.tencent.tpns:fcm:[VERSION]-release' // FCM 推送 [VERSION] 为当前 SDK 版本号,版本号可在 Android SDK 发布动态查看
implementation 'com.google.firebase:firebase-messaging:17.6.0'
//在应用级的 gradle 文件的最后一行代码中新增并将 google-services.json 放进您应用 model 的根路径下
apply plugin: 'com.google.gms.google-services'
注意:
- FCM 推送 [VERSION] 为当前 SDK 版本号,版本号可在 Android SDK 发布动态 查看。
- Google 配置 google-play-services(建议版本 17.0.0+,较低版本有可能出现无法注册 FCM 风险)。
在调用移动推送注册代码 XGPushManager.registerPush 前,添加以下代码设置:
XGPushConfig.enableOtherPush(this, true);
注册 FCM 成功的日志如下:
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
-keep class com.google.firebase.** {*;}
说明:混淆规则需要放在 App 项目级别的 proguard-rules.pro 文件中。
在手机设置-应用管理-具体应用-点击“结束运行”/“强制停止”等按钮停止了应用。大部分国内品牌手机,在多任务页面划掉应用进程,也可认为是强制停止了应用进程(境外手机不会)。
本页内容是否解决了您的问题?