Integrating Custom Push Services with IMIconnectCoreSDK

Extending the FirebaseMessagingService

If your application uses its own FirebaseMessagingService or another third-party FCM push provider, you will also need to forward the onNewToken and onMessageReceived calls to the IMIconnectCoreSDK.

Below is the sample code for extending your own FirebaseMessagingService

public class MyFirebaseMessagingService extends FirebaseMessagingService {
  private static final String TAG = "MyMessagingService";
  @Override
  public void onNewToken() {
    try {
      ICMessaging.getInstance().processPushToken(
          getApplicationContext(), token);
    } catch (ICException e) {
      Log.e(TAG, "onNewToken()", e);
    }
  }
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    try {
      if (ICMessaging.getInstance().isConnectPushData(
              remoteMessage.getData())) {
        ICMessaging.getInstance().processPushData(remoteMessage.getData());
      }
    } catch (ICException e) {
      Log.e(TAG, "onMessageReceived", e);
    }
  }
}

Extending the HmsMessageService

If your application uses its own HmsMessageService or another third-party HMS push provider, you will also need to forward the onNewToken and onMessageReceived calls to the IMIconnectCoreSDK.

Below is the sample code for extending your own HmsMessagingService

public class MyHmsMessageService extends HmsMessageService {
  private static final String TAG = "MyHmsMessageService ";
  @Override
  public void onNewToken() {
    try {
      ICHMSPushProvider.processPushToken(getApplicationContext(), token);
    } catch (ICException e) {
      Log.e(TAG, "onNewToken()", e);
    }
  }
  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    try {
      if (ICMessaging.getInstance().isConnectPushData(
              remoteMessage.getDataOfMap())) {
        ICMessaging.getInstance().processPushData(remoteMessage.getDataOfMap());
      }
    } catch (ICException e) {
      Log.e(TAG, "onMessageReceived", e);
    }
  }
}