All Products
Search
Document Center

Access HUAWEI Push

Last Updated: Sep 13, 2021

This guide mainly introduces the process of accessing HUAWEI Push. The process falls into three steps:

  1. Register HUAWEI Push
  2. Access HUAWEI Push
  3. Test HUAWEI Push

Register HUAWEI Push

Visit the Huawei Developer official website, register an account, and enable the push service. For more information, see Enable HUAWEI Push.

Access HUAWEI Push

MPS supports access to Huawei HMS2 and HMS5. However, you can only select HMS2 or HMS5 in the process of accessing Huawei push component.

  • The HMS2 is obsolete. If you are accessing HUAWEI Push for the first time, you are recommended to access HMS5.
  • If you have upgraded from HMS2 to HMS5, you need to delete the HMS2 AndroidManifest configuration listed below first.

The following describes the access methods of Huawei HMS2 and HMS5 respectively.

Access HUAWEI Push - HMS5.x version

  1. Add Push - HMS5 component in the IDE plugin. The steps are roughly the same as adding MPS SDK, see Add SDK.

    Note: The Push - HMS5 component only contains adaptive codes, without HMS SDK. You can add the HMS SDK dependencies separately by following the steps below.
  2. Download the configuration file agconnect-services.json in the Huawei App Service Console and place it under the assets directory of the main project.

  3. Configure the Maven warehouse address of HMS SDK in the build.gradle file in the project root directory.
       
    1. allprojects {
    2. repositories {
    3. // Other repos are ignored
    4. maven {url 'https://developer.huawei.com/repo/'}
    5. }
    6. }
  4. Add HMS SDK dependencies in the build.gradle file of the main project.
       
    1. dependencies {
    2. implementation 'com.huawei.hms:push:5.0.2.300'
    3. }
    • The HMS SDK version is updated frequently. For the latest version, refer to HMS SDK Version Change History.
    • The current adaptable version is 5.0.2.300. If you need to use a higher version, you can change it by yourself. Generally, the vendor’s SDK is downward compatible. If it is not compatible, you can submit a ticket about the adaption issue.
  5. To use obfuscation, you need to add the related obfuscation configurations.

Access HUAWEI Push - HMS2.x version

  1. Add Push - HMS2 component in the IDE plugin. The steps are roughly the same as adding MPS SDK, see Add SDK.
    The current HMS2 SDK version is V2.5.2.201.
  2. Configure AndroidManifest.xml, and replace the value of com.huawei.hms.client.appid. If you access the MiPush SDK through Portal & Bundle projects, please configure the AndroidManifest.xml in the Portal project.

       
    1. <activity
    2. android:name="com.huawei.hms.activity.BridgeActivity"
    3. android:configChanges="orientation|locale|screenSize|layoutDirection|fontScale"
    4. android:excludeFromRecents="true"
    5. android:exported="false"
    6. android:hardwareAccelerated="true"
    7. android:theme="@android:style/Theme.Translucent">
    8. <meta-data
    9. android:name="hwc-theme"
    10. android:value="androidhwext:style/Theme.Emui.Translucent" />
    11. </activity>
    12. <!--To prevent dex crashing in an earlier version, dynamically enable provider, and set "enabled" to false.-->
    13. <provider
    14. android:name="com.huawei.hms.update.provider.UpdateProvider"
    15. android:authorities="${applicationId}.hms.update.provider"
    16. android:exported="false"
    17. android:enabled="false"
    18. android:grantUriPermissions="true">
    19. </provider>
    20. <!-- Replace the "appid" of value with the actual app ID in the service details of the app on Huawei Developer. Keep the slash (\) and space in the value. -->
    21. <meta-data
    22. android:name="com.huawei.hms.client.appid"
    23. android:value="\ your huawei appId" />
    24. <receiver
    25. android:name="com.huawei.hms.support.api.push.PushEventReceiver"
    26. >
    27. <intent-filter>
    28. <!-- Receive the notification bar message sent by the channel. It is compatible with earlier versions of PUSH.-->
    29. <action android:name="com.huawei.intent.action.PUSH" />
    30. </intent-filter>
    31. </receiver>
    32. <receiver
    33. android:name="com.alipay.pushsdk.thirdparty.huawei.HuaweiPushReceiver"
    34. android:process=":push">
    35. <intent-filter>
    36. <!-- Required, used for receiving TOKEN. -->
    37. <action android:name="com.huawei.android.push.intent.REGISTRATION" />
    38. <!-- Required, used for receiving messages -->
    39. <action android:name="com.huawei.android.push.intent.RECEIVE" />
    40. <!-- Optional, used for triggering onEvent callback upon a click on the notification bar or the button on the notification bar -->
    41. <action android:name="com.huawei.android.push.intent.CLICK" />
    42. <!-- Optional, used for checking whether the PUSH channel is connected. You do not need to configure this parameter if access check is not required -->
    43. <action android:name="com.huawei.intent.action.PUSH_STATE" />
    44. </intent-filter>
    45. </receiver>
  3. To use obfuscation, you need to add the related obfuscation configurations.
    • If you accessed HUAWEI push SDK through Native AAR, you need to add mPaaS obfuscation rules.
    • If you accessed HUAWEI push SDK through other methods, you don’t have to add any obfuscation configuration.

Test HUAWEI Push

  1. After accessing HUAWEI Push, you can start the app on your Huawei phone, and the MPS SDK will automatically get the HUAWEI Push token and report it. Before you start the app, make sure that you have called the initialization method, see Message push initialization.
  2. Push test messages when the app process is killed:
    • If you can still receive the messages, it means that the app has successfully accessed HUAWEI Push.
    • If you cannot receive the messages, you can follow the steps below for troubleshooting.

Troubleshooting

  1. Check if the Huawei configuration and parameters are consistent with that in the Huawei push backend.
    • For HMS2, check if AndroidManifest.xml has related configurations added, and check if com.huawei.hms.client.appid is same as that in Huawei push backend.
    • For HMS5, check if agconnect-services.json exists, and the file is correctly placed.
  2. Check if HUAWEI Push is enabled in the mPaaS console (see Configure HUAWEI Push), and the relevant configurations are consistent with that on Huawei push backend.
  3. View the logs in Logcat to troubleshoot:

    1. Select the push process, filter mPush.PushProxyFactory, and check if the following log exists:
           
      1. D/mPush.PushProxyFactory: found proxy com.mpaas.push.external.hms.Creator (HMS2)
      2. D/mPush.PushProxyFactory: found proxy com.mpaas.push.external.hms5.Creator (HMS5)
      If not, it means that there may be a problem with the Push - HMS2 or Push - HMS5 component. Check if the component has been correctly added.
    2. Select the main process, filter mHMS, and check if the channel token of HUAWEI Push has been obtained. If the following log (get token failed) appears:
       token

      It means the system failed to get the channel token, see HUAWEI Push Result Codes for the failure reason.

    3. Select the main process, filter report channel token, check if the channel token of HUAWEI Push has been successfully reported. If the following log appears:

           
      1. report channel token error: xxxx

      It means the channel token reporting failed, you need to check if the base64Code in the mPaaS configuration file has a value, and check if the apk signature that you uploaded when obtaining the configuration file is consistent with the app.

  4. If the above steps do not resolve the issue, you can submit a ticket or contact the mPaaS support staff.

Other questions

Does MPS has any version restrictions on EMUI and Huawei mobile services

There are version restrictions on Emotion UI (EMUI for short, it is an Android-based emotional operating system developed by Huawei) and Huawei mobile services.

For detailed version requirements, see Conditions for devices to receive Huawei notifications.

Failed to print logs for Huawei mobile phones

On the dialing interface of the Huawei mobile phone, enter ##2846579## to enter Project menu > Background settings > LOG settings and select AP Logs. After the phone restarts, Logcat will start to take effect.