Huawei channel integration

Last updated: 2020-07-13 16:23:05

    Operation Scenarios

    The Huawei push channel is a system-level push channel officially provided by Huawei. On a Huawei phone, push messages can be delivered through Huawei's system channel without opening the application.

    • Huawei Push can only receive push messages in a signed package environment.
    • The Mobile Push Service on the Huawei phone must be upgraded to 2.5.3 or above; otherwise, the Huawei channel registration will fail and the TPNS channel will be used.
    • The Huawei channel supports click callback (custom parameters required) and passthrough (custom parameters ignored but arrival unguaranteed) but not arrival callback.


    Getting key

    1. Enter the Huawei's development platform.
    2. Sign up for a developer account and log in to the platform. For more information, please see Account Registration and Verification. (If you are registering a new account, you need to verify your identity.)
    3. Create an application on the Huawei Push platform. For more information, please see Creating App. (The application package name must be the same as that entered in the TPNS Console.)
    4. Get and copy the application's AppID and AppSecret and paste them in Application Configuration > Huawei Channel in the TPNS Console.

    Configuring SHA256 certificate fingerprint

    For more information on how to get the SHA256 certificate fingerprint, please see the Huawei Push integration documentation.

    Integration steps

    Integrating through Android Studio

    Complete the configuration required by TPNS in the build.gradle file in the Application module and then add the following Huawei nodes:

    1. Configure the Huawei AppID. The sample code is as follows:

      manifestPlaceholders = [
        HW_APPID: "Huawei APPID"
    2. Import the dependencies related to Huawei Push. The sample code is as follows:

      implementation 'com.tencent.tpns:huawei:[VERSION]-release'// Huawei Push [VERSION] is the version number of the current SDK, which can be viewed on the SDK download page

    Integrating through Eclipse

    1. Download the SDK installation package.
    2. Open the Other-Push-jar folder and import the jar packages related to Huawei Push. Import hw4tpns1.1.2.1.jar to the project folder:
    3. Add the following configuration to the Androidmanifest.xml file:
               android:value="your `APPID` (from Huawei's official website)" >
               android:theme="@android:style/Theme.Translucent" >
                       android:value="androidhwext:style/Theme.Emui.Translucent" />
               android:authorities="application package name.hms.update.provider"
               android:grantUriPermissions="true" >
       <receiver android:name="" >
                       <!-- Receive notification bar messages from the channel, which is compatible with the legacy version of PUSH -->
                       <action android:name="com.huawei.intent.action.PUSH" />
       <!-- Note: this is the end required by Huawei Push -->
    4. Add the receiver to AndroidManifest.xml and configure it as follows:
      <receiver android:name="" >
           <!-- Required; used to receive `TOKEN` -->
           <action android:name="" />
           <!-- Required; used to receive messages -->
           <action android:name="" />
           <!-- Optional; used to trigger the `onEvent` callback after the notification bar or a button in it is clicked -->
           <action android:name="" />
           <!-- Optional; used to check whether the PUSH channel is connected to; not needed if there is no need to view -->
           <action android:name="com.huawei.intent.action.PUSH_STATE" />

    Enabling Huawei Push

    Enable the third-party push API before calling TPNS' XGPushManager.registerPush:

    // Enable the third-party push
    XGPushConfig.enableOtherPush(getApplicationContext(), true);

    The log of successful registration is as follows:

    I/XINGE: [XGOtherPush] other push token is : 0865551032618726300001294600CN01 other push type: huawei
     I/XINGE: [a] binder other push token with accid = 2100274337  token = 17c32948df0346d5837d4748192e9d2f14c81e08 otherPushType = huawei otherPushToken = 0865551032618726300001294600CN01

    Code obfuscation

    -keepattributes *Annotation*
    -keepattributes Exceptions
    -keepattributes InnerClasses
    -keepattributes Signature
    -keepattributes SourceFile,LineNumberTable
    -keep class**{*;}
    -keep class com.huawei.updatesdk.**{*;}
    -keep class com.huawei.hms.**{*;}
    -keep class**{*;}

    Obfuscation rules must be stored in the file at the application project level.

    Arrival Receipt Configuration for Huawei Channel

    The arrival receipt for the Huawei channel should be configured by yourself. After configuring this feature as instructed in Configuration Guide, you can view the arrival data for the Huawei push channel in the push records.

    Badge Adaptation for Huawei Devices

    Huawei devices support setting application badge in the following steps:

    1. Apply for the permission to set application badge by adding the following permission configuration under the manifest tag in the application's AndroidManifest.xml file:
      <uses-permission android:name=" "/>
    2. Set the application startup class
      You need to enable the Huawei channel in the console and enter the Activity class of the application entry corresponding to the homescreen icon in parameter configurations, such as com.test.badge.MainActivity as shown below:

      For the usage of the badge, please see Badge Adaptation Guide.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback