As TPNS always keeps up with the update progress of each vendor channel's push service, it provides plugin dependency packages integrated with HMS Core Push SDK for your choice.
Note:
- For Huawei Push, you can successfully register with the Huawei channel and push messages through it only in a signed package environment.
- The Huawei channel supports click callback but not arrival callback.
AppID
and AppSecret
and paste them into TPNS Console > Configuration Management > Basic Configuration > Huawei Official Push Channel.Get the SHA-256 certificate fingerprint and configure it on the Huawei Push platform as instructed in Generating Signature Certificate Fingerprint.
Log in to the Huawei Developer platform, go to My Projects > select a project > Project Settings, and download the latest configuration file agconnect-services.json
of your Huawei application.
Enable the push service in Development > Push Service on the Huawei Push platform. For more information, please see Enabling Push Service.
build.gradle
file in the Android project-level directory, add the Huawei repository address and HMS Gradle plugin dependencies under repositories and dependencies in buildscript, respectively:buildscript {
repositories {
google()
jcenter()
maven {url 'http://developer.huawei.com/repo/'} // Huawei Maven repository address
}
dependencies {
// Other `classpath` configurations
classpath 'com.huawei.agconnect:agcp:1.3.1.300' // Gradle plugin dependencies of Huawei Push
}
}
build.gradle
file in the Android project-level directory, add the Huawei dependency repository address under repositories in allprojects:allprojects {
repositories {
google()
jcenter()
maven {url 'http://developer.huawei.com/repo/'} // Huawei Maven repository address
}
}
agconnect-services.json
obtained from the Huawei Push platform to the app
module directory.build.gradle
file at its beginning in the app
module:// Other Gradle plugins of application
apply plugin: 'com.huawei.agconnect' // HMS Push SDK Gradle plugin
android {
// Application configuration content
}
build.gradle
file under the app
module:dependencies {
// ...Other dependencies of the program
implementation 'com.tencent.tpns:huawei:[VERSION]-release' // Huawei Push [VERSION] is the version number of the current latest SDK, which can be viewed in SDK for Android Updates
implementation 'com.huawei.hms:push:5.0.2.300' // HMS Core Push module dependency package
}
Note:
- Huawei Push [VERSION] is the version number of the current latest SDK, which can be viewed in SDK for Android Updates.
- Starting v1.2.1.3, TPNS SDK for Android officially supports Huawei Push v5. Please use TPNS Huawei dependency v1.2.1.3 or above to avoid integration conflicts.
If you cannot access Huawei Maven repository in your internal development environment, you can try the following manual integration method:
Other-Push-jar
folder and import the dependent packages related to huaweiv5 by copying all jar and aar packages into the project.build.gradle
file in the Android project-level directory, add HMS Gradle plugin dependencies under dependencies in buildscript:buildscript {
repositories {
google()
jcenter()
}
dependencies {
// Other `classpath` configurations
classpath files('app/libs/agcp-1.3.1.300.jar') // Gradle plugin dependencies of Huawei Push
}
}
agconnect-services.json
obtained from the Huawei Push platform to the app
module directory.build.gradle
file at its beginning in the app
module:// Other Gradle plugins of application
apply plugin: 'com.huawei.agconnect' // HMS Push SDK v4 Gradle plugin
android {
// Application configuration content
}
build.gradle
file under the app
module:dependencies {
// ...Other dependencies of the program
implementation files('libs/tpns-huaweiv5-1.2.1.1.jar') // TPNS plugin for HMS Core
implementation fileTree(include: ['*.aar'], dir: 'libs') // HMS Core Push module dependency package
}
<application>
and </application>
tags in the manifest
file:<application>
<service
android:name="com.huawei.android.hms.tpns.HWHmsMessageService"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.push.action.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
Enable the third-party push API before calling the TPNS registration API XGPushManager.registerPush
:
// Enable the third-party push
XGPushConfig.enableOtherPush(getApplicationContext(), true);
The log of successful registration is as follows:
V/TPush: [XGPushConfig] isUsedOtherPush:true
E/xg.vip: get otherpush errcode: errCode : 0 , errMsg : success
V/TPush: [XGPushConfig] isUsedOtherPush:true
I/TPush: [OtherPushClient] handleUpdateToken other push token is : IQAAAACy0PsqAADxfCrWG3kupbOraeAiYoo9n2B-bAfb2d--kctc8E_UnY_mrIdg9ionukZvC******dVD8GlJi_5-0rpskunnNMcat35HA other push type: huawei
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
-keep class com.huawei.agconnect.**{*;}
Note:
Obfuscation rules must be stored in the
proguard-rules.pro
file at the application project level.
The arrival receipt for the Huawei channel should be configured by yourself. After configuring this feature as instructed in Acquisition of Vendor Channel Arrival Receipt, you can view the arrival data for the Huawei push channel in the push records.
You can set the application badge on Huawei devices after applying for the application badge setting permission and setting the application start class. For more information, please see Badge Adaption Guide.
The Huawei Push service has strict requirements on the connection configuration. If you fail to register with the Huawei channel, you can use one of the following ways to get the Huawei Push registration error code:
OtherPush
or HMSSDK
to view the return code logs.Starting EMUI 10.0, Huawei Push intelligently categorizes notification messages into two levels: general and important. Versions below EMUI 10.0 don't categorize notifications but have only one level, so all notifications are displayed through the "default notification" channel, which is equivalent to the important level on EMUI 10.0. If a notification is categorized as "general", there will be no vibration, sound, or status bar icon alerts for it. Currently, the notification level can be set to "important" through the custom notification channel; however, according to the applicable Huawei Push rules, the final display effect will still be determined jointly by the set level and the level calculated by Huawei Push's intelligent categorization, and the lower level will prevail; for example, if the two levels are "important" and "general", "general" will prevail. For more information, please see Vendor Message Categorization Feature Use Instructions.
When your application is released on Huawei AppGallery, it may fail the audit with the error message "Error:28: you need to package the certificate file into the APK when integrating with HMS. Please directly copy the assets directory to the application project's root directory" displayed. Please fix the problem as follows:
assets
directory to that in your application project. If the assets
directory does not exist in the application project, create one.
Was this page helpful?