Huawei Push

更新时间:
复制 MD 格式

Integrate Huawei Push into your mPaaS app in three steps: register with Huawei, integrate the HMS SDK, and verify delivery.

  1. Register with Huawei Push

  2. Integrate Huawei Push

  3. Test Huawei Push

Register with Huawei Push

On the Huawei Developers website, create a developer account and enable the push service. For step-by-step instructions, see Steps to enable Huawei Push.

Integrate Huawei Push

The Push SDK supports Huawei Mobile Services (HMS) 2 and HMS 5. Choose one version — you cannot integrate both.

  • HMS 5 (recommended): Use this for all new integrations.

  • HMS 2 (legacy): If you are upgrading to HMS 5, first remove the HMS 2 AndroidManifest configuration before proceeding.

Integrate Huawei Push - HMS 5.x version

  1. Add the Push - HMS5 component using the same method as adding the Push SDK. For details, see Add the Push SDK.

    Note

    The Push - HMS5 component contains only adapter code and does not include the HMS SDK. You must add the HMS SDK dependency separately, as described in the following steps.

  2. In the Huawei AppGallery Connect console, download the agconnect-services.json configuration file and place it in the assets folder of your app's main project.

  3. In the root-level build.gradle, add the HMS SDK Maven repository.

    allprojects {
     repositories {
         // Other repos are omitted.
         maven {url 'https://developer.huawei.com/repo/'}
     }
    }
  4. In the app-level build.gradle, add the HMS SDK dependency.

     dependencies {
         implementation 'com.huawei.hms:push:5.0.2.300'
     }
    • For the latest HMS SDK version, see HMS SDK version update notes.

    • The currently adapted version is 5.0.2.300. Vendor SDKs are generally backward compatible, so you can use a later version. If you encounter compatibility issues, join DingTalk group 145930007362 to request support.

  5. If your build uses obfuscation, add the following configurations:

Integrate Huawei Push - HMS 2.x version

  1. Add the Push - Huawei 2 component using the same method as adding the Push SDK. For details, see Add the SDK. The built-in HMS 2 SDK version is 2.5.2.201.

  2. Configure the AndroidManifest.xml file. For component-based integration, add this in the Portal project. Replace the com.huawei.hms.client.appid value with your app's actual Huawei app ID.

     <activity
          android:name="com.huawei.hms.activity.BridgeActivity"
          android:configChanges="orientation|locale|screenSize|layoutDirection|fontScale"
          android:excludeFromRecents="true"
          android:exported="false"
          android:hardwareAccelerated="true"
          android:theme="@android:style/Theme.Translucent">
           <meta-data
              android:name="hwc-theme"
              android:value="androidhwext:style/Theme.Emui.Translucent" />
     </activity>
      <!--To prevent crashes on earlier DEX versions, dynamically enable the provider. Set enabled to false.-->
      <provider
           android:name="com.huawei.hms.update.provider.UpdateProvider"
           android:authorities="${applicationId}.hms.update.provider"
           android:exported="false"
           android:enabled="false"
           android:grantUriPermissions="true">
         </provider>
             <!-- Replace "appid" in the value with the actual app ID from the service details of your application on the Huawei Developers website. Note: Keep the backslash (\) and the space in the value.-->
       <meta-data
                 android:name="com.huawei.hms.client.appid"
                 android:value="\ your huawei appId" />
         <receiver
                 android:name="com.huawei.hms.support.api.push.PushEventReceiver"
                 android:exported="true"
                 >
                 <intent-filter>
                     <!-- Receives notification messages from the channel. Compatible with earlier PUSH versions. -->
                     <action android:name="com.huawei.intent.action.PUSH" />
                 </intent-filter>
      </receiver>
    
       <receiver
                 android:name="com.alipay.pushsdk.thirdparty.huawei.HuaweiPushReceiver"
                 android:exported="true"
                 android:process=":push">
                 <intent-filter>
                     <!-- Required. Used to receive the TOKEN. -->
                     <action android:name="com.huawei.android.push.intent.REGISTRATION" />
                     <!-- Required. Used to receive messages. -->
                     <action android:name="com.huawei.android.push.intent.RECEIVE" />
                     <!-- Optional. Triggers the onEvent callback when a notification or a button in a notification is clicked. -->
                     <action android:name="com.huawei.android.push.intent.CLICK" />
                     <!-- Optional. Checks if the PUSH channel is connected. Not required if you do not need to check the connection. -->
                     <action android:name="com.huawei.intent.action.PUSH_STATE" />
                 </intent-filter>
        </receiver>
  3. If your build uses obfuscation, add the following configurations:

Test Huawei Push

  1. Launch the app on a Huawei device and confirm that the push initialization method is called. For details, see Message Push Service Initialization. The Push SDK automatically gets and reports the Huawei Push vendor token.

  2. Kill the app process, then send a test push message.

    • If you receive the message, Huawei Push is integrated successfully.

    • If you do not receive the message, follow the troubleshooting steps below.

Troubleshoot push delivery

  1. Verify that the Huawei configuration matches what is set in the Huawei Push backend:

    • HMS 2: confirm the required entries are in AndroidManifest.xml and that com.huawei.hms.client.appid matches the app ID in the Huawei Push backend.

    • HMS 5: confirm that agconnect-services.json exists and is in the correct location.

  2. Verify that the Huawei channel is enabled in the mPaaS console and that its settings match those in the Huawei Push backend. For details, see Channel Configuration.

  3. Check logcat to diagnose further:

    1. In the push process, filter for mPush.PushProxyFactory. Confirm one of the following log entries is present:

      D/mPush.PushProxyFactory: found proxy com.mpaas.push.external.hms.Creator (HMS2)
      D/mPush.PushProxyFactory: found proxy com.mpaas.push.external.hms5.Creator (HMS5)

      If neither entry appears, the Push - Huawei 2 or Push - HMS5 component was not added correctly. Re-check the component setup.

    2. In the main process, filter for mHMS to confirm the Huawei Push vendor token was obtained. If the log shows get token failed, token retrieval failed. Look up the error code in Huawei Push error codes.

    3. In the main process, filter for report channel token to confirm the vendor token was reported. If you see:

      report channel token error: xxxx

      Token reporting failed. Check that the base64Code in the mPaaS configuration file is not empty and that the APK signature uploaded when you got the configuration file matches the current app's signature.

Other issues

Version requirements for Emotion UI and Huawei Mobile Services

Huawei devices must meet minimum version requirements for Emotion UI (EMUI) and Huawei Mobile Services (HMS) to receive push messages. For the full requirements, see Conditions for devices to receive Huawei push messages.

Cannot print logs on a Huawei device

In the phone's dialer, enter ##2846579## to open the Project Menu. Go to Background settings > LOG settings and select AP Log. Restart the device for the changes to take effect.