1.mob推送平台中的【故障排查】功能,切换到海外版的是搜不到regId的。
2.海外版的TCP通道,非常不稳。几乎收不到信息,无论是否设置了代理。
3.需要接入FCM通道
FCM接入主要流程:
1.FCM创建项目,拿到google-services.json文件,放入app下。
2.FCM创建项目完成后,从项目设置->服务账号中,生成新的私钥。
3.Mob平台国内版推送配置,导入FCM生成的私钥,然后同步到海外版。
4.配置FCM通道,进行FCM相关下载
MobPush {
debugLevel 4
devInfo {
//FCM推送通道配置
FCM{
//设置默认推送通知显示图标
iconRes "@mipmap/ic_launcher"
version "20.2.0"
}
}
5.项目级.gradle文件中添加:
classpath 'com.google.gms:google-services:4.3.10'//fcm
app.gradle文件中添加fcm插件:
plugins {
id 'com.google.gms.google-services'//fcm
}
6.同步下项目,新建Receiver。将收到的消息,创建通知栏显示。
class FCMRev : FirebaseMessagingService() {
override fun onNewToken(fcmTokne: String) {
super.onNewToken(fcmTokne)
Log.e("mob", "fcm toke :$fcmTokne")
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
val title = remoteMessage.notification?.title
val body = remoteMessage.notification?.body
Log.e("mob", "fcm message :$title , body :$body")
if (title.isNullOrEmpty() || body.isNullOrEmpty()) {
return
}
val intent = Intent(this, MainActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
// val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT)
val channelId = "Default"
val builder: NotificationCompat.Builder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(body).setAutoCancel(true)
// .setContentIntent(pendingIntent)
val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
channelId,
"Default channel",
NotificationManager.IMPORTANCE_DEFAULT
)
manager.createNotificationChannel(channel)
}
manager.notify(0, builder.build())
}
}
AndroidManifest.xml中注册:
<service
android:name=".receiver.FCMRev"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
7.完成集成。可以在MOB平台或者FCM平台中测试推送。