The Mi push channel is a system-level push channel officially provided by Mi. On a Mi phone, push messages can be delivered through Mi's system channel without opening the application.
Note:
- The Mi channel supports arrival callback but not click callback.
- When you test message push through the Mi channel, avoid using words such as
test
; otherwise, the messages will be blocked by Mi and marked as "unimportant messages".
Enable the push service for the application on Mi Open Platform > Push Platform.
AppId
, AppKey
, and AppSecret
. For more information, please see Quick Connection Guide.AppId
, AppKey
, and AppSecret
parameters of the application into TPNS Console > Configuration Management > Basic Configuration > Xiaomi Official Push Channel.JCenter is recommended for dependency import for AS development. Import the Jar package of Mi Push:
implementation 'com.tencent.tpns:xiaomi:[VERSION]-release'// Mi Push [VERSION] is the version number of the current SDK, which can be viewed in SDK for Android Updates
Note:
Mi Push [VERSION] is the version number of the current SDK, which can be viewed in SDK for Android Updates.
Other-Push-jar
folder and import the jar packages related to Mi Push. Import xm4tpns1.1.2.1.jar
to the project folder.<application>
<service
android:name="com.xiaomi.push.service.XMPushService"
android:enabled="true"
android:process=":pushservice" />
<service
android:name="com.xiaomi.push.service.XMJobService"
android:enabled="true"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE"
android:process=":pushservice" />
<!-- Note: this service must be added for version 3.0.1 or above -->
<service
android:name="com.xiaomi.mipush.sdk.PushMessageHandler"
android:enabled="true"
android:exported="true" />
<service
android:name="com.xiaomi.mipush.sdk.MessageHandleService"
android:enabled="true" />
<!-- Note: this service must be added for version 2.2.5 or above -->
<receiver
android:name="com.xiaomi.push.service.receivers.NetworkStatusReceiver"
android:exported="true" >
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<receiver
android:name="com.xiaomi.push.service.receivers.PingReceiver"
android:exported="false"
android:process=":pushservice" >
<intent-filter>
<action android:name="com.xiaomi.push.PING_TIMER" />
</intent-filter>
</receiver>
</application>
<!-- Note: this is the beginning of permission required by Mi Push -->
<permission
android:name="application package name.permission.MIPUSH_RECEIVE"
android:protectionLevel="signature" />
<!-- Here, change application package name to the actual application package name -->
<uses-permission android:name="application package name.permission.MIPUSH_RECEIVE" />
<!-- Here, change application package name to the actual application package name -->
<!-- Note: this is the end of the permissions required by Mi Push -->
Receiver
in AndroidManifest.xml
and configure it as follows:<receiver
android:exported="true"
android:name="com.tencent.android.mipush.XMPushMessageReceiver">
<intent-filter>
<action android:name="com.xiaomi.mipush.RECEIVE_MESSAGE" />
</intent-filter>
<intent-filter>
<action android:name="com.xiaomi.mipush.MESSAGE_ARRIVED" />
</intent-filter>
<intent-filter>
<action android:name="com.xiaomi.mipush.ERROR" />
</intent-filter>
</receiver>
Set Mi AppID
and AppKey
.
XGPushConfig.setMiPushAppId(getApplicationContext(), "APPID");
XGPushConfig.setMiPushAppKey(getApplicationContext(), "APPKEY");
// Enable the third-party push
XGPushConfig.enableOtherPush(getApplicationContext(), true);
// The log of successful registration is as follows:
I/TPush: [OtherPushClient] handleUpdateToken other push token is : 3CvDLfyPRArAGnv****dvQ7rYko+OthWo90rW+Edeqn53RUudp6U1dhySpV35 other push type: xiaomi
I/TPush: [PushServiceBroadcastHandler] >> bind OtherPushToken success ack with [accId = 1500001048 , rsp = 0] token = 03be2036762f******33bce72d40eb5e677a otherPushType = xiaomi otherPushToken = 3CvDLfyPRArAGnv****dvQ7rYko+OthWo90rW+Edeqn53RUudp6U1dhySpV35G
If you need to get parameters through the click callback or redirect to a custom page, you can use the intent to do so. For more information, please see FAQs for Android.
-keep class com.xiaomi.**{*;}
-keep public class * extends com.xiaomi.mipush.sdk.PushMessageReceiver
Note:
Obfuscation rules must be stored in the
proguard-rules.pro
file at the application project level.
Was this page helpful?