Files
zhini_im/荣耀推送配置内容.txt
rw0067680 c01808ac21 first commit
Change-Id: Ib7c2ab10a2562044fcaf9879388a6cbc1db6ac61
2025-12-23 10:00:49 +08:00

79 lines
2.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
配置Manifest文件
配置通知栏消息权限
如果您需要在Android 13及以上的荣耀设备上展示通知栏消息需要申请通知栏权限。
<manifest ...>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</manifest>
配置AppId信息
您需要在AndroidManifest.xml文件下添加meta-data标签并在com.hihonor.push.app_id下添加您的 AppIdAppId在注册完成后获取用于配置您的设备。
<manifest ...>
<application>
<meta-data
android:name="com.hihonor.push.app_id"
android:value="您的AppId" />
</application>
</manifest>
创建消息接收服务
HonorMessageService是用于接收新PushToken和接收透传消息的服务。
继承HonorMessageService并且重写onNewToken方法和onMessageReceived方法。
public class MyHonorMsgService extends HonorMessageService {
//Token发生变化时会以onNewToken方法返回
@Override
public void onNewToken(String pushToken) {
// TODO: 处理新token。
}
@Override
public void onMessageReceived(HonorPushDataMsg msg) {
// TODO: 处理收到的透传消息。
}
}
注意:
由于onNewToken会在init方法设置为true时回调。建议增加网络权限校验和用户同意协议校验。
如果透传消息传递敏感的信息:如个人身份证、金钱、银行卡信息、关键业务指令等,建议您对消息内容进行加密处理,进一步进行安全防护。
注册服务
您需要在AndroidManifest.xml文件的application标签下注册您自己的service。
exported属性需要设置为false限制其他应用的组件唤醒该service。
<manifest ...>
<application>
<service
android:name="com.hihonor.push.sdk.demo.service.MyHonorMsgService"
android:exported="false">
<intent-filter>
<action android:name="com.hihonor.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
如果您的应用targerSdkVersion大于等于30需要在 AndroidManifest.xml 中添加标签用于查找到对应的action。
<manifest ...>
<queries>
<intent>
<action android:name="com.hihonor.push.action.BIND_PUSH_SERVICE" />
</intent>
</queries>
</manifest>
配置混淆脚本
您编译APK前需要配置混淆配置文件避免混淆PushSDK导致功能异常。
在应用级根目录下打开混淆配置文件proguard-rules.pro加入排除PushSDK的混淆配置脚本。
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hihonor.push.**{*;}
上一篇
集成SDK