This guide mainly introduces the process of integrating HUAWEI Push. The process falls into three steps:
Register HUAWEI Push
Visit the Huawei Developer official website, register an account, and enable the push service. For more information, see Enable HUAWEI Push.
Integrate HUAWEI Push
MPS supports access to Huawei HMS2 and HMS5. However, you can only select HMS2 or HMS5 in the process of integrating Huawei push component.
The HMS2 is obsolete. If you are integrating HUAWEI Push for the first time, you are recommended to integrate HMS5.
If you have upgraded from HMS2 to HMS5, you need to delete the HMS2
AndroidManifest
configuration listed below first.
The following describes the integration methods of Huawei HMS2 and HMS5 respectively.
HUAWEI Push - HMS5.x version
Add Push - HMS5 component in the IDE plugin. The steps are roughly the same as adding MPS SDK, see Add SDK.
NoteThe Push - HMS5 component only contains adaptive codes, without HMS SDK. You can add the HMS SDK dependencies separately by following the steps below.
Download the configuration file
agconnect-services.json
in the Huawei App Service Console and place it under theassets
directory of the main project.Configure the Maven warehouse address of HMS SDK in the
build.gradle
file in the project root directory.allprojects { repositories { // Other repos are ignored maven {url 'https://developer.huawei.com/repo/'} } }
Add HMS SDK dependencies in the
build.gradle
file of the main project.dependencies { implementation 'com.huawei.hms:push:5.0.2.300' }
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 give feedback to adapt to the needs of the new version
To use obfuscation, you need to add the related obfuscation configurations.
No matter which integration method is used in integrating HUAWEI push SDK, you need to add Huawei push obfuscation rules.
If you integrated HUAWEI push SDK through Native AAR, you need to add mPaaS obfuscation rules.
HUAWEI Push - HMS2.x version
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.
Configure
AndroidManifest.xml
, and replace the value ofcom.huawei.hms.client.appid
. If you integrate the MiPush SDK through Portal & Bundle projects, please configure theAndroidManifest.xml
in the Portal project.<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 dex crashing in an earlier version, dynamically enable provider, and 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 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. --> <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> <!-- Receive the notification bar message sent by the channel. It is compatible with earlier versions of PUSH.--> <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 for receiving TOKEN. --> <action android:name="com.huawei.android.push.intent.REGISTRATION" /> <!-- Required, used for receiving messages --> <action android:name="com.huawei.android.push.intent.RECEIVE" /> <!-- Optional, used for triggering onEvent callback upon a click on the notification bar or the button on the notification bar --> <action android:name="com.huawei.android.push.intent.CLICK" /> <!-- Optional, used for checking whether the PUSH channel is connected. You do not need to configure this parameter if access check is not required --> <action android:name="com.huawei.intent.action.PUSH_STATE" /> </intent-filter> </receiver>
To use obfuscation, you need to add the related obfuscation configurations.
If you integrated HUAWEI push SDK through Native AAR, you need to add mPaaS obfuscation rules.
If you integrated HUAWEI push SDK through other methods, you don’t have to add any obfuscation configuration.
Test HUAWEI Push
After integrating 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.
Push test messages when the app process is killed:
If you can still receive the messages, it means that the app has successfully integrated HUAWEI Push.
If you cannot receive the messages, you can follow the steps below for troubleshooting.
Troubleshooting
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 ifcom.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.
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.
View the logs in Logcat to troubleshoot:
Select the
push
process, filtermPush.PushProxyFactory
, and check if the following log exists: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 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.
Select the main process, filter
mHMS
, and check if the channel token of HUAWEI Push has been obtained. If the following logget token failed
appears:It means the system failed to get the channel token, see HUAWEI Push Result Codes for the failure reason.
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: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.
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.