Overriding the SDK's Components

This section is helpful for those who want to override the SDK's core features like Push Notification rendering, Push Click handling etc.

  1. Override FCM Services
    1.1. BlueshiftInstanceIdService
    1.2. BlueshiftMessagingService
  2. Override Notification Clicks

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

The client app can override the messaging framework of Blueshift Android SDK.

 

1.1. BlueshiftInstanceIdService

Note: From Blueshift Android SDK v2.0.2 we have removed this service as FirebaseInstanceIdService is deprecated now. Check release Notes of v2.0.2.

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>
 

1.2. BlueshiftMessagingService

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();
  }
}

From Blueshift Android SDK version v2.0.2 and above, if you want to get the FCM token when it gets refreshed, you need to add the following method to the above class (YourMessaginService).

@Override
public void onNewToken(String newToken) {
super.onNewToken(newToken);

/*
* Use the new token in your app. the super call is important for the
* SDK to do the analytical part and notification rendering. Make sure
* that it is present when you override onNewToken() method.
*/
}

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>

From v2.1.1 we have deprecated the BlueshiftNotificationEventsService class. Instead of using below code, please follow this documentation to override the notification clicks.

To override the click actions on notifications rendered by Blueshift Android SDK, follow the steps given below.

Step #1: Override BlueshiftNotificationEventsService

public class YourServiceName extends BlueshiftNotificationEventsService {

    @Override
    public void openApp(Context context, Bundle bundle) {
        /*
         * This method is called whenever an action to open app
         * is fired on a notification click. This is the default
         * action taken on notification clicks when no category
         * is provided.
         *
         * Override this to take your own action on this.*/
    }

    @Override
    public void addToCart(Context context, Bundle bundle) {
        /*
         * This method is called when 'Buy' button is clicked from a notification
         * that has category 'buy'.
         *
         * Override this to take your own action on this.*/
    }

    @Override
    public void displayProductPage(Context context, Bundle bundle) {
        /*
         * This method is called when 'View' button is clicked from a notification
         * that has category 'buy'.
         *
         * Override this to take your own action on this.*/
    }

    @Override
    public void displayCartPage(Context context, Bundle bundle) {
        /*
         * This method is called when notification with category 'view_cart'
         * is being clicked.
         *
         * Override this to take your own action on this.*/
    }

    @Override
    public void displayOfferDisplayPage(Context context, Bundle bundle) {
        /*
         * This method is called when notification with category 'promotion'
         * is being clicked.
         *
         * Override this to take your own action on this.*/
    }
}

Step #2: Update AndroidManifest.xml

<service android:name="your.pkg.name.YourServiceName">
    <intent-filter>
        <action android:name="com.blueshift.NOTIFICATION_CLICK_EVENT" />
    </intent-filter>
</service>
Was this article helpful?
0 out of 0 found this helpful