Override FCM - Deprecated in v2.0.2

If you would like to have your own push receiver to handle all the push messages coming from Blueshift and other channels who use FCM, you need to override the FCM implementation done by the Blueshift Android SDK. This is required if you want to get callback when FCM token changes.

Note: This change requires SDK version 1.1.2.fcm or above

Override InstanceId Service

The following steps will help you override the Blueshift's implementation of FCM Instance Id Service. This helps the client app to get access to the token change event when it occurs.

Step #1: Extend the class BlueshiftInstanceIdService to get notified when the FCM token gets refreshed.

public class YourInstanceIdService extends BlueshiftInstanceIdService {

  @Override
  public void onTokenRefresh() {
    super.onTokenRefresh(); // this is required for the SDK to function properly.

    String newToken = FirebaseInstanceId.getInstance().getToken();
    // use the newToken as require.
  }
}

Step #2: Register the service inside AndroidManifest.xml

<service
    android:name="your.package.name.YourInstanceIdService">
    <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
    </intent-filter>
</service>
 

Override Messaging Service

The following steps will help you override the Blueshift's implementation of FCM Messaging Service. This helps the client app to get access to the push message payload when it comes to the device.

Step #1: Extend the class BlueshiftMessagingService to get notified when a new push message is received.

public class YourMessagingService extends BlueshiftMessagingService {

  @Override
  public void onMessageReceived(RemoteMessage remoteMessage) {
    /*
    * It is important to keep the super.onMessageReceived() call if you
    * want the sdk to do the notification rendering for push messages
    * coming from the Blueshift server. If you want to completely override
    * the notification rendering, skip this call and implement your code. */

    super.onMessageReceived();
  }
}

Step #2: Register the service inside AndroidManifest.xml

<service
    android:name="your.package.name.YourMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>
 
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request