This topic describes the three-step process for integrating Huawei Push.
Register with Huawei Push
Log on to the official Huawei Developers website, create an account, and enable the push service. For more information, see Steps to enable Huawei Push.
Integrate Huawei Push
The Push SDK supports integration with Huawei Mobile Services (HMS) 2 and HMS 5. You can only integrate one of these versions.
HMS 2 is an older version. For new integrations, use HMS 5.
If you are upgrading from HMS 2 to HMS 5, you must first delete the HMS 2
AndroidManifestconfiguration.
Integrate Huawei Push - HMS 5.x version
Add the Push - HMS5 component. The method is the same as adding the Push SDK. For more information, see Add the Push SDK.
NoteThe 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.
In the Huawei AppGallery Connect console, download the
agconnect-services.jsonconfiguration file and place it in theassetsfolder of your app's main project.In the
build.gradlefile in the project's root directory, configure the Maven repository address for the HMS SDK.allprojects { repositories { // Other repos are omitted. maven {url 'https://developer.huawei.com/repo/'} } }In the
build.gradlefile of the main project, add the HMS SDK dependency.dependencies { implementation 'com.huawei.hms:push:5.0.2.300' }The HMS SDK version is updated frequently. For the latest version, see HMS SDK Version Update Notes.
The currently adapted version is 5.0.2.300. You can modify it as needed to use a later version. Vendor SDKs are usually backward compatible. If you encounter compatibility issues, join DingTalk group 145930007362 to request support for the new version.
To use obfuscation, add the required obfuscation configurations:
All connection types require you to add the Huawei Push obfuscation rules.
If you use the AAR connection type, you also need to add mPaaS obfuscation rules.
Integrate Huawei Push - HMS 2.x version
Add the Push - Huawei 2 component. The method is the same as adding the Push SDK. For more information, see Add the SDK. The current built-in HMS 2 SDK version is 2.5.2.201.
Configure the
AndroidManifest.xmlfile (for component-based integration, add it in the Portal project) and replace the value ofcom.huawei.hms.client.appid.<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>To use obfuscation, add the required obfuscation configurations:
If you use the AAR connection type, you need to add mPaaS obfuscation rules.
If you use other connection types, no action is required.
Test Huawei Push
After integrating Huawei Push, start your application on a Huawei phone and ensure that the initialization method is called. For more information, see Message Push Service Initialization. The Push SDK automatically obtains and reports the Huawei Push vendor token.
Send a test message after you kill the application process:
If you receive the message, the integration with Huawei Push is successful.
If you do not receive the message, follow the steps below to troubleshoot the issue.
Troubleshoot problems
Verify that the Huawei configurations and parameters match those in the Huawei Push backend:
For HMS 2 integration, verify that the required configurations are added to
AndroidManifest.xmland that thecom.huawei.hms.client.appidvalue matches the one in the Huawei Push backend.For HMS 5 integration, verify that the
agconnect-services.jsonfile exists and is in the correct location.
Verify that the Huawei channel is enabled in the mPaaS console and that the configurations match those in the Huawei Push backend. For more information, see Configure the Huawei push channel.
Check the logcat logs to troubleshoot issues:
Select the push process and filter for
mPush.PushProxyFactory. Look for the following log entry: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 this log is not present, there may be an issue with adding the Push - Huawei 2 or Push - HMS5 component. Verify that the component was added correctly.
Select the main process and filter for
mHMS. Check if the Huawei Push vendor token was obtained. If the log showsget token failed, the attempt to obtain the vendor token failed. For more information about error codes, see Huawei Push Error Codes.Select the main process and filter for
report channel token. Check if the Huawei vendor token was reported successfully. If the following log appears:report channel token error: xxxxThis log indicates that reporting the vendor token failed. Verify that the
base64Codein the mPaaS configuration file has a value and that the APK signature that you uploaded when you obtained the configuration file matches the signature of the current application.
Other issues
Version restrictions for EMUI and Huawei Mobile Services
There are version restrictions for Emotion UI (EMUI), an operating system developed by Huawei based on Android, and for Huawei Mobile Services. For detailed version requirements, see Conditions for devices to receive Huawei push messages.
Cannot print logs on a Huawei phone
In the phone's dialer, enter *#*#2846579#*#* to open the Project Menu. Go to Background settings > LOG settings and select AP Log. You must restart the phone for the changes to take effect.