操作场景
魅族推送通道是由魅族官方提供的系统级推送通道。在魅族手机上,推送消息能够通过魅族的系统通道抵达终端,并且无需打开应用,即可收到推送。
说明:
魅族推送通道通知标题不超过32字符,通知内容不超过100字符。
魅族推送通道不支持透传消息。
操作步骤
获取密钥
1. 进入 魅族推送官网,注册并登录开发者账号,获取 AppID、AppKey、AppSecret 三个密钥参数。更多详情请参见 魅族开发文档。 2. 复制应用的 AppId、AppKey 和 AppSecret 参数填入 移动推送控制台>配置管理>基础配置>魅族官方推送通道栏目中。 集成方式
AndroidStudio 集成
implementation 'com.tencent.tpns:meizu:[VERSION]-release'
Eclipse 集成
2. 打开 Other-Push-jar 文件夹, 导入魅族推送相关 jar 包,将 mz4tpns1.1.2.1.jar 导入项目工程中。
3. 请在主工程添加以下类资源文件:
package com.meizu.cloud.pushinternal;
public class R {
public static final class drawable {
public static final int stat_sys_third_app_notify = com.tencent.android.tpns.demo.R.drawable.stat_sys_third_app_notify;
}
}
4. 在 AndroidManifest 文件添加以下配置:
<application>
<service
android:name="com.meizu.cloud.pushsdk.NotificationService"
android:exported="true" />
<receiver
android:name="com.meizu.cloud.pushsdk.MzPushSystemReceiver"
android:exported="false"
android:permission="com.meizu.flyme.permission.PUSH">
<intent-filter>
<action android:name="com.meizu.flyme.push.intent.PUSH_SYSTEM" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="com.meizu.flyme.permission.PUSH" />
<uses-permission android:name="com.meizu.flyme.push.permission.RECEIVE"></uses-permission>
<permission
android:name="${applicationId}.push.permission.MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.push.permission.MESSAGE"></uses-permission>
<uses-permission android:name="com.meizu.c2dm.permission.RECEIVE" />
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature"></permission>
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
5. 魅族消息 receiver:在 AndroidManifest.xml
增加 Receiver
配置如下:
<receiver
android:name="com.tencent.android.mzpush.MZPushMessageReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.meizu.flyme.push.intent.MESSAGE" />
<action android:name="com.meizu.flyme.push.intent.REGISTER.FEEDBACK"/>
<action android:name="com.meizu.flyme.push.intent.UNREGISTER.FEEDBACK"/>
<action android:name="com.meizu.c2dm.intent.REGISTRATION" />
<action android:name="com.meizu.c2dm.intent.RECEIVE" />
<category android:name="应用包名"></category>
</intent-filter>
</receiver>
6. Flyme 6.0 及以下版本的魅族手机,使用手动集成方式,需要在 drawable 不同分辨率的文件夹下对应放置一张名称必须为 stat_sys_third_app_notify 的图片,详情请参见 移动推送 Android SDK 中魅族厂商依赖目录的 flyme-notification-res 文件夹。 开启魅族推送
在启动移动推送,调用 XGPushManager.registerPush
之前,配置如下代码:
XGPushConfig.enableOtherPush(context, true);
XGPushConfig.setMzPushAppId(this, APP_ID);
XGPushConfig.setMzPushAppKey(this, APP_KEY);
注册成功的日志如下:
I/TPush: [OtherPushClient] handleUpdateToken other push token is : V5R5b7c02********47744c6b635e464b527e487802 other push type: meizu
I/TPush: [PushServiceBroadcastHandler] >> bind OtherPushToken success ack with [accId = 150000**** , rsp = 0] token = 0398291156ce7d2f****66bd0952c87c372f otherPushType = meizu otherPushToken = V5R5b7c02********47744c6b635e464b527e487802
代码混淆
1. 将以下混淆规则添加在 App 项目级别的 proguard-rules.pro 文件中。
-dontwarn com.meizu.cloud.pushsdk.**
-keep class com.meizu.cloud.pushsdk.**{*;}
说明:
若出现 App Debug 版本注册魅族 token 正常,但在 Release 版本中无法获取,请升级 SDK 1.3.2.0 及以上版本。
2. 如应用使用了 AndResGuard 插件,请在 AndResGuard 配置白名单中添加以下内容。如果未使用 AndResGuard 插件,则请忽略该步骤。
whiteList = [
"R.drawable.stat_sys_third_app_notify"
]
魅族通道抵达回执配置
魅族通道抵达回执需要开发者自行配置,您可参照 魅族厂商通道回执配置指引 进行配置,完成后,可在推送记录中查看魅族推送通道的抵达数据。 常见问题排查
魅族推送注册失败错误码查询方法
若您观察到如下类似日志则说明魅族厂商通道注册失败,开发者可以通过以下方式获取魅族推送注册错误码:
[OtherPushClient] handleUpdateToken other push token is : other push type: mezu
推送服务 debug 模式下,过滤关键字 “OtherPush” ,查看相关返回码日志(例如 [OtherPush_XG_MZ] onRegisterStatus BasicPushStatus{code='110000', message='appId不合法'}
),并前往 厂商通道注册失败排查指南 查找对应原因,获取解决办法。 厂商通道下发失败:客户端/服务端错误码:500,是什么原因?
本页内容是否解决了您的问题?