
基础产品
适用各种通信场景,接入灵活

融合场景
专为场景打造,接入成本低

扩展能力
核心能力延展,功能全面

更多服务
一站式服务,满足各种需求
回答:
同时集成融云和极光的推送,配置会有冲突,主要解决思路,暂时将融云配置相关位置去掉。
本文只标注了gradle 和AndroidManifest.xml 中需要合并修改的位置
实现本文相关配置前需要配合融云推送文档,集成融云推送。具体启用推送服务,请参考融云推送文档。
https://docs.rongcloud.cn/v4/5X/views/im/ui/guide/notify/push/android.html
如果接入极光推送就不需要重复导入三方推送的jar包,只需要导入jiguang组合包就可以。(只有oppo 厂商 aar 需要单独引入,请将 jiguang/libs 下 com.heytap.msp-push-x.x.x.aar 单独拷贝一份到应用 module/libs 下)。
⚠️注意:集成下面步骤前要先把极光组合包集成完成才可以。
**以下所有三方推送内容都需要先集成了极光组合包**
implementation project(':jiguang')
- 小米极光组合包
XIAOMI_APPID : "MI-小米appid",XIAOMI_APPKEY : "MI-小米appkey",
在Androidmanifest中添加
<!-- 小米 配置开始 < --> <permission android:name="${applicationId}.MIPUSH_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="${applicationId}.permission.MIPUSH_RECEIVE" /> <!-- 小米 配置结束 < --> <!-- 小米 配置开始 < --> <service android:name="com.xiaomi.push.service.XMPushService" android:enabled="true" /> <service android:name="com.xiaomi.mipush.sdk.PushMessageHandler" android:enabled="true" android:exported="true" /> <service android:name="com.xiaomi.mipush.sdk.MessageHandleService" android:enabled="true" /> <!--注:此service必须在2.2.5版本以后(包括2.2.5版本)加入--> <service android:name="com.xiaomi.push.service.XMJobService" android:enabled="true" android:exported="false" android:permission="android.permission.BIND_JOB_SERVICE" /> <!--注:此service必须在3.0.1版本以后(包括3.0.1版本)加入--> <receiver android:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver" android:exported="true"> <intent-filter> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> <receiver android:name="com.xiaomi.push.service.receivers.PingReceiver" android:exported="false"> <intent-filter> <action android:name="com.xiaomi.push.PING_TIMER" /> </intent-filter> </receiver> <receiver android:name="io.rong.push.platform.mi.MiMessageReceiver" android:exported="true"> <intent-filter> <action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" /> </intent-filter> <intent-filter> <action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" /> </intent-filter> <intent-filter> <action android:name="com.xiaomi.mipush.ERROR" /> </intent-filter> </receiver> <!-- 小米 配置结束 < -->
如果使用了 proguard,需要在配置文件中加入,可以防止一个误报的 warning 导致无法成功编译,
-dontwarn com.xiaomi.push.** -keep class com.xiaomi.push.** { *; }
- VIVO极光组合包
在Mainfest中添加
<!-- vivo 推送服务需要配置的 service、activity --> <service android:name="com.vivo.push.sdk.service.CommandClientService" android:exported="true"/> <activity android:name="com.vivo.push.sdk.LinkProxyClientActivity" android:exported="false" android:screenOrientation="portrait" android:theme="@android:style/Theme.Translucent.NoTitleBar"/> <!-- vivo push 推送 receiver 声明 --> <receiver android:name="io.rong.push.platform.vivo.VivoPushMessageReceiver" > <intent-filter> <!-- 接收 vivo push 消息 --> <action android:name="com.vivo.pushclient.action.RECEIVE" /> </intent-filter> </receiver> <meta-data android:name="com.vivo.push.api_key" android:value="您的api_key"/> <meta-data android:name="com.vivo.push.app_id" android:value="您的app_id"/>
⚠️注意:**vivo推送需要应用上线通过审核才可收到极光测试推送,否则会收不到消息(错误码:10045--应用审核中,不可发送正式消息),或者需要再vivo平台添加测试设备才可收到推送**
若需要混淆 app,请在混淆文件中添加以下说明,防止 SDK 内容被二次混淆.
-dontwarn com.vivo.push.** -keep class com.vivo.push.**{*; } -keep class com.vivo.vms.**{*; }
- OPPO极光组合包
在应用 module gradle 中添加 OPPO 账号配置
android { ...... defaultConfig { applicationId "com.xxx.xxx" //JPush 上注册的包名. ...... manifestPlaceholders = [ JPUSH_PKGNAME : applicationId, JPUSH_APPKEY : "你的 Appkey ", //JPush 上注册的包名对应的 Appkey. JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可. OPPO_APPKEY : "OP-OPPO的APPKEY", OPPO_APPID : "OP-OPPO的APPID", OPPO_APPSECRET: "OP-OPPO的APPSECRET", ] ...... } ......} dependencies { ...... // oppo 厂商 aar 需要单独引入 // 请将 jiguang/libs 下 com.heytap.msp-push-x.x.x.aar 单独拷贝一份到应用 module/libs 下 implementation(name: 'com.heytap.msp-push-2.1.0', ext: 'aar') }
如果使用了 proguard,需要在配置文件中加入,可以防止一个误报的 warning 导致无法成功编译
-dontwarn com.coloros.mcsdk.** -keep class com.coloros.mcsdk.** { *; } -dontwarn com.heytap.**-keep class com.heytap.** { *; } -dontwarn com.mcs.**-keep class com.mcs.** { *; }
⚠️注意:
**接收 OPPO 推送需要用户的 oppo 手机开启应用的通知权限。**
**OPPO推送暂时只支持通知栏消息的推送。消息下发到 OS 系统模块并由系统通知模块展示,在用户点击通知前,不启动应用。**
OPPO 推送的机型和规则等相关内容请参考 OPPO PUSH FAQ (opens new window)
- 魅族极光组合包
1. 需要厂商通道回执配置,需要去魅族官网进行配置,**配置成功后给极光发送邮件**,参考文档https://docs.jiguang.cn/jpush/client/Android/android_callback/#_4
2. 对于同一个应用集成了多个推送SDK,且其他SDK也使用了魅族通道的用户: 可以将这个极光内置的Receiver,换成自己定义的Receiver。 这个Receiver必须继承魅族的com.meizu.cloud.pushsdk.MzPushMessageReceiver 且在每个回调方法,都回调给极光的PluginMeizuPlatformsReceiver。类似于这样:
public class MyMZPushReceiver extends MzPushMessageReceiver { final PluginMeizuPlatformsReceiver receiver = new PluginMeizuPlatformsReceiver(); @Override public void onReceive(Context context, Intent intent) { receiver.onReceive(context, intent); } @Override public void onRegister(Context context, String s) { receiver.onRegister(context, s); } @Override public void onMessage(Context context, String s) { receiver.onMessage(context, s); } @Override public void onNotificationArrived(Context context, MzPushMessage mzPushMessage) { receiver.onNotificationArrived(context, mzPushMessage); } @Override public void onNotificationClicked(Context context, MzPushMessage mzPushMessage) { receiver.onNotificationClicked(context, mzPushMessage); } @Override public void onUnRegister(Context context, boolean b) { receiver.onUnRegister(context, b); } @Override public void onPushStatus(Context context, PushSwitchStatus pushSwitchStatus) { receiver.onPushStatus(context, pushSwitchStatus); } @Override public void onRegisterStatus(Context context, RegisterStatus registerStatus) { receiver.onRegisterStatus(context, registerStatus); } @Override public void onUnRegisterStatus(Context context, UnRegisterStatus unRegisterStatus) { receiver.onUnRegisterStatus(context, unRegisterStatus); } @Override public void onSubTagsStatus(Context context, SubTagsStatus subTagsStatus) { receiver.onSubTagsStatus(context, subTagsStatus); } @Override public void onSubAliasStatus(Context context, SubAliasStatus subAliasStatus) { receiver.onSubAliasStatus(context, subAliasStatus); } @Override public void onUpdateNotificationBuilder(PushNotificationBuilder pushNotificationBuilder) { receiver.onUpdateNotificationBuilder(pushNotificationBuilder); } }
在Androidmanifest中添加
<!-- MeiZu 配置开始 < --> <!-- 兼容 flyme5.0 以下版本,魅族内部集成 pushSDK 必填,不然无法收到 消息--> <uses-permission android:name="com.meizu.flyme.push.permission.RECEIVE"/> <permission android:name="您的包名.push.permission.MESSAGE" android:protectionLevel="signature"/> <uses-permission android:name="您的包名.push.permission.MESSAGE"/> <!-- 兼容 flyme3.0 配置权限--> <!-- MeiZu 配置结束 < --> <!-- MeiZu 配置开始 < --> <receiver android:name=".push.MyMZPushReceiver"> <intent-filter> <!-- 接收 push 消息 --> <action android:name="com.meizu.flyme.push.intent.MESSAGE"/> <!-- 接收 register 消息 --> <action android:name="com.meizu.flyme.push.intent.REGISTER.FEEDBACK" /> <!-- 接收 unregister 消息--> <action android:name="com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK"/> <!-- 兼容低版本 Flyme3 推送服务配置 --> <action android:name="com.meizu.c2dm.intent.REGISTRATION"/> <action android:name="com.meizu.c2dm.intent.RECEIVE" /> <category android:name="您的包名"/> </intent-filter> </receiver> <!-- MeiZu 配置结束 < -->
如果使用了 proguard,需要在配置文件中加入,可以防止一个误报的 warning 导致无法成功编译,
-dontwarn com.meizu.cloud.** -keep class com.meizu.cloud.** { *; }
- 华为推送组合包
**1.添加 Huawei SDK 到项目中**
在根级 build.gradle 中添加规则,以纳入 HMS 服务插件 和 华为 的 Maven 代码库,可根据华为开发者联盟发布的版本更新选择最新版本:
buildscript { repositories { google() jcenter() mavenCentral() maven { url 'http://developer.huawei.com/repo/'} } dependencies { classpath 'com.huawei.agconnect:agcp:1.4.2.300' } } allprojects { repositories { google() jcenter() mavenCentral() maven {url 'http://developer.huawei.com/repo/'} } }
在 app 模块的 build.gradle 添加
dependencies { // 接入华为厂商 implementation 'com.huawei.hms:push:5.3.0.301' }
在应用 module 的 build.gradle 文件底部添加 apply plugin 代码行,以启用 gradle 插件:
// ADD THIS AT THE TOP apply plugin: 'com.huawei.agconnect'
**2. 配置接收 HMS 消息的服务**
对于同一个应用集成了多个推送SDK,且其他SDK也使用了华为通道的用户: 可以将这个极光内置的 Service,换成自己定义的 Service。 这个 Service 必须继承华为的 com.huawei.hms.push.HmsMessageService 且在每个回调方法,都回调给极光的 PluginHuaweiPlatformsService。类似于这样:
public class MyHWPushService extends HmsMessageService { final PluginHuaweiPlatformsService service = new PluginHuaweiPlatformsService(); @Override public void onNewToken(String s) { service.onNewToken(s); } @Override public void onMessageReceived(RemoteMessage remoteMessage) { service.onMessageReceived(remoteMessage); } @Override public void onMessageSent(String s) { service.onMessageSent(s); } @Override public void onSendError(String s, Exception e) { service.onSendError(s,e); } @Override public void onDeletedMessages() { service.onDeletedMessages(); } }
<!--华为开始--> <service android:name=".push.MyHWPushService" android:exported="false"> <intent-filter> <action android:name="com.huawei.push.action.MESSAGING_EVENT" /> </intent-filter> </service> <!-- 华为结束-->
**3.在build.gradle中配置在华为后台添加的指纹证书对应的签名**
注:HMS 服务必须要求 app 签名才能注册成功。指纹证书是在终端采用keytool -list -v -keystore keystorefileName 获取偶对应的指纹证书.
在 project 的 build.gradle 添加 如下内容
signingConfigs { release { storeFile file("../youmeng.jks") storePassword '123456' keyAlias 'key0' keyPassword '123456' } debug { storeFile file("../youmeng.jks") storePassword '123456' keyAlias 'key0' keyPassword '123456' } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' signingConfig signingConfigs.release } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' signingConfig signingConfigs.debug } }
**成功集成华为厂商通道的标志**
插件集成成功后,会向华为server请求token,拿到这个token即可证明 集成没问题。
token是可以在日志里查到的,观察极光日志输出:
**贴图**
完成华为厂商通道 SDK 集成后,需要开发者在华为开放平台开通并配置消息回执,方可把华为的送达统计等数据回调到极光平台,具体操作如下:* 登录华为AppGallery Connect网站,选择需要开通推送服务的应用,进入应用服务页面
* 左侧导航选择**增长**-**推送服务**,在右侧配置页面选择**配置**-**服务状态**-**回执状态**,点击`开通`按钮
* 华为开通回执功能页面如下,填写相关信息
* 回调地址:可将极光回调地址 https://xpnscb.jpush.cn/v3/hpnsreport
* HTTPS证书:可以通过命令:openssl s_client -connect xpnscb.jpush.cn:443 -showcerts 来获取证书
> 说明:
> 旧回调地址:https://report.jpush.cn/v3/hpnsreport 需尽快切换到新回调地址:https://xpnscb.jpush.cn/v3/hpnsreport
到此小米、vivo、oppo、魅族、华为推送都就集成完成了,特别提醒:**一定要仔细检查各个三方推送的appKey、appId、appSecret等参数是否填写正确!!!**