This guide mainly introduces the process of integrating MiPush. The process falls into three steps:
Register MiPush
Complete MiPush registration with reference to the following official Xiaomi documents:
Integrate MiPush
Add Push - Xiaomi component in the IDE plugin. The steps are roughly the same as adding MPS SDK, see Add SDK. Currently, the built-in MiPush SDK is V4.0.2. You can see Release notes to learn the historical versions.
Configure
AndroidManifest.xml
, and replace the values ofxiaomi_appid
andxiaomi_appkey
. If you integrate the MiPush SDK through Portal & Bundle projects, please configure theAndroidManifest.xml
in the Portal project.<permission android:name="${applicationId}.permission.MIPUSH_RECEIVE" android:protectionLevel="signature"/> <uses-permission android:name="${applicationId}.permission.MIPUSH_RECEIVE"/> <application> <!-- Keep the slash (\) and space in the value --> <meta-data android:name="xiaomi_appid" android:value="\ 2xxxxxxxxxxxxxxx" /> <!-- Keep the slash (\) and space in the value --> <meta-data android:name="xiaomi_appkey" android:value="\ 5xxxxxxxxxxxxxxx" /> </application>
Test MiPush
After integrating MiPush, you can start the app on your Xiaomi phone, and the MPS SDK will automatically get the MiPush 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 MiPush.
If you cannot receive the messages, you can follow the steps below for troubleshooting.
Troubleshooting
Check if
AndroidManifest.xml
has been configured, and the values ofxiaomi_appid
andxiaomi_appkey
in the file are consistent with that on Mi Developer Platform.Check if MiPush is enabled in the mPaaS console (see Configure Xiaomi push channel), and the relevant configurations are consistent with that on Mi Developer Platform.
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.mi.Creator
If not, it means that there may be a problem with the Push - Xiaomi component. Check if the component has been correctly added.
Select the
push
, filtermMi
, and check if the MiPush channel token has been obtained.If the following log (register_fail) appears, it means the MiPush registration failed. See MiPush error codes for the failure reason (
reason
). If the value ofreason
is UNKNOWN, it is generally due to incorrectxiaomi_appid
orxiaomi_appkey
. To learn about the result codes (resultCode
), see MiPush server error codes.Select the main process, filter
report channel token
, check if the MiPush channel token 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.