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

Xiaomi Push Notifications

📘

Note

You can skip these steps if you don't want to use Xiaomi push gateway to send 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 Smartech SDK use below snippet.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Smartech smartech = Smartech.getInstance(new WeakReference<>(this));
        smartech.initializeSdk(this);
        MiPushClient.registerPush(this, "XIAOMI_APP_ID", "XIAOMI_APP_KEY");
        String xiaomiToken = MiPushClient.getRegId(this);
        smartech.setXiaomiPushToken(xiaomiToken);
    }
}

Getting Xiaomi Push RegId/Token

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

Smartech.getInstance(new WeakReference<>(context)).getXiaomiPushToken();

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 isFromSmartech = Smartech.getInstance(new WeakReference<>(context)).handleXiaomiNotification(message.getContent());
        if (!isFromSmartech) {
            //Handle notification from other sources.
        }
    }
}