MobPush海外版接入FCM

1.mob推送平台中的【故障排查】功能,切换到海外版的是搜不到regId的。

2.海外版的TCP通道,非常不稳。几乎收不到信息,无论是否设置了代理。

3.需要接入FCM通道

FCM接入主要流程:

参考:MobTech集成文档-MobTech

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平台中测试推送。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值