These docs are for v1.0. Click to read the latest docs for v2.0.

Xiaomi Push Notifications

Chinese smartphones have occupied a large part smartphone market. To achieve longer battery support Chinese smartphones impose some restrictions on background processes. Due to these restrictions, many users are unable to receive push notifications.

To improve the notification delivery, Smartech has now added the support of the Xiaomi Push gateway. Smartech will send notifications through both Xiaomi push and FCM push gateway to increase the chances of delivery to the end-users. We ensure that the user will receive the given push notification only once.

Xiaomi Push Integration Steps

You need to perform a few steps to integrate Xiaomi Push in your app.

  1. Create a Xiaomi Developer account.
  2. Create an application on Xiaomi Push Console.
  3. To receive the push messages form Xiaomi, enable push from Xiaomi admin console.
  4. Download Xiaomi Push SDK.
  5. Follow Xiaomi Android SDK integration docs and integrate Xiaomi Push SDK into your project.

Setting Xiaomi Push Token/RegId

Similar to FCM, Xiaomi Push has Xiaomi Reg Id/Token which can be used to send push notifications to a device. To pass Xiaomi reg id/token to Netcore SDK use below snippet.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        MiPushClient.registerPush(this, "XIAOMI_APP_ID", "XIAOMI_APP_KEY");
        String xiaomiToken = MiPushClient.getRegId(this);
        NetcoreSDK.setXiaomiPushToken(this, xiaomiToken);
    }
}

Getting Xiaomi Push RegId/Token

To retrieve the Xiaomi token set in the Netcore SDK use the below code.

NetcoreSDK.getXiaomiPushToken(context);

Handle Xiaomi Push Notifications

Notifications sent via Xiaomi push are received in the custom BroadcastReceiver class which extends PushMessageReceiver of Xiaomi SDK. Make the below changes in the onReceivePassThroughMessage() of your broadcast receiver. You don't need to trigger notification delivery and open event manually if you are using the above method.

public class XiaomiPushReceiver extends PushMessageReceiver {
    @Override
    public void onReceivePassThroughMessage(Context context, MiPushMessage message) {
        boolean isFromNetcore = NetcoreSDK.handleXiaomiNotification(context, message.getContent());
        if (!isFromNetcore) {
            //Handle notification from other sources.
        }
    }
}

Send Notification Delivery Event

In case you don't want to use handleNotification() and want to render Smartech notification on your own, Smartech recommends sending the delivery event. Use deliverXiaomiNotificationEvent() method of NetcoreSDK to trigger delivery event.

public class XiaomiPushReceiver extends PushMessageReceiver {
    @Override
    public void onReceivePassThroughMessage(Context context, MiPushMessage message) {
        try {
            boolean isFromNetcore = NetcoreSDK.isNotificationFromNetcore(new JSONObject(message.getContent()));
            if (isFromNetcore) {
                JSONObject payload = new JSONObject(message.getContent());
                NetcoreSDK.renderNotification(context, payload); // Or you can use your own way to render notification.
                NetcoreSDK.deliverXiaomiNotificationEvent(context, payload); // Send delivery events if notification from Smartech. 
            } else {
                //Handle notification from other sources.
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

Send Notification Open/Click Event

To trigger notification open/click event for Smartech notifications, call the openXiaomiNotificationEvent() of NetcoreSDK at the place where you are handling notification click. You need to pass the Json object of message content you received in the onReceivePassThroughMessage().

NetcoreSDK.openXiaomiNotificationEvent(context,new JSONObject(payload));

Note: Xiaomi Push Notifications support is available in AndroidX versions of Netcore SDK starting from 2.2.17 and from 2.2.10 in Smartech-Apxor SDK.