Callbacks

Callbacks are useful for understanding the lifecycle stages of WebEngage messages. All WebEngage callbacks are called on the main thread.

Push message callbacks

Implement your class with PushNotificationCallbacks and register it to WebEngage.

import com.webengage.sdk.android.WebEngage;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        WebEngage.registerPushNotificationCallback(new PushNotificationCallbacksImpl());
    }
}

Push Notification Received

This callback is invoked before push notification is shown. This allows you to customize the push message data received from WebEngage.

PushNotificationData onPushNotificationReceived(Context context, PushNotificationData pushNotificationData);

Push Notification Shown

This callback is invoked after the notification is shown.

void onPushNotificationShown(Context context, PushNotificationData pushNotificationData);

Push Notification Clicked

This callback is invoked when the user clicks the main intent (i.e. primary call to action) of the notification.

Return true if the click was handled by your app, or false to let WebEngage SDK handle it.

boolean onPushNotificationClicked(Context context, PushNotificationData pushNotificationData);

Push Notification Action Clicked

This callback is invoked when the user clicks the non-primary call to action button (if any) of the notification.

Return true if the click was handled by your app, or false to let WebEngage SDK handle it.

boolean onPushNotificationActionClicked(Context context, PushNotificationData pushNotificationData, String buttonId);

Push Notification Dismissed

This callback is invoked when the user dismisses the notification either by swiping it away or by clearing system notification tray.

void onPushNotificationDismissed(Context context, PushNotificationData pushNotificationData);

Read operation on PushNotificationData fields can be done from any push notification callback function.

Any changes done to PushNotificationData fields will be reflected only if they are called from onPushNotificationReceived callback. For example : notificationData.getPrimeCallToAction().setAction("http://www.example.com", CallToAction.TYPE.LINK,context) will be effective only if it is called from onPushNotificationReceived.

In-app message callbacks

In-app message callbacks can help you prevent conflicts with views in your app.

Implement your class with InAppNotificationCallbacks and register it to WebEngage.

import com.webengage.sdk.android.WebEngage;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        WebEngage.registerInAppNotificationCallback(new InAppNotificationCallback());
    }
}

In-app Message Received

This callback is invoked before the in-app message is shown to your users. It allows you to customize the UI, colors, CTAs (buttons) and content of the In-app message received from WebEngage before displaying it to your users.

InAppNotificationData onInAppNotificationPrepared(Context context, InAppNotificationData inAppNotificationData);

In-App Message Shown

This callback is invoked after the message is shown.

void onInAppNotificationShown(Context context, InAppNotificationData inAppNotificationData);

In-App Message Clicked

This callback is invoked when the user clicks the message. The ID of the button clicked is passed as actionId.

Return true if the click was handled by your app, or false to let WebEngage SDK handle it.

boolean onInAppNotificationClicked(Context context, InAppNotificationData inAppNotificationData, String actionId);

In-App Message Dismissed

This callback is invoked when the user dismisses the message.

void onInAppNotificationDismissed(Context context, InAppNotificationData inAppNotificationData);

Notification Callback Data (InAppNotificationData inAppNotificationData)

Data received from in-app callbacks adheres to the below format.

{
    "canClose": true,
    "layoutAttributes": {
        "posX": 0,
        "posY": 0,
        "TITLE_ALIGN": "CENTER",
        "image_url": "http://s3-ap-southeast-1.amazonaws.com/wk-test-static-files/76a9d10/a6b6e04d-43e9-4c09-b15f-8acffbcfcc1a.jpg",
        "TITLE_WRAP": false,
        "wvWidth": 100,
        "type": "BLOCKING",
        "wvHeight": 100,
        "fullScreen": false
    },
    "showTitle": true,
    "notificationEncId": "~13ssb59",
    "description": null,
    "canMinimize": true,
    "id": "173046a46",
    "isActive": true,
    "title": "My Title",
    "actions": [{
        "actionText": "Puma",
        "actionEId": "~64c71b",
        "actionTarget": "_top",
        "type": "DEEP_LINK",
        "actionLink": "webengage://com.webengage.inapptest/start_activity/com.webengage.inapptest.Activity1",
        "isPrime": true
    }],
    "config": {
        "titleColor": "#ffffff",
        "c2aBackgroundColor": "#411ad3",
        "c2aTextFont": "Open Sans",
        "titleFont": "Open Sans",
        "c2aTextColor": "#f7f2f2",
        "hideLogo": false
    },
    "direction": "ltr"
}

Lifecycle callbacks

Lifecycle callbacks allow you to listen to GCM registered, GCM received, app installed and app upgraded events.

Implement your class with LifeCycleCallbacks and register it to WebEngage.

import com.webengage.sdk.android.WebEngage;

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        WebEngage.registerLifeCycleCallback(new LifeCycleCallbacksImpl());
    }
}

GCM Registered

void onGCMRegistered(Context context, final String regID);

GCM Message Received

void onGCMMessageReceived(Context context, final Intent intent);

App Installed

void onAppInstalled(Context context, final Intent intent);

App Upgraded

void onAppUpgraded(Context context, final int oldVersion, final int newVersion);

State change callbacks

State change callbacks are triggered whenever the state of the SDK changes.

Extend your class with StateChangeCallbacks and register it to WebEngage.

import com.webengage.sdk.android.WebEngage;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        WebEngage.registerStateChangeCallback(new StateChangeCallbackImpl());
    }
}

It is recommended to register StateChangeCallbacks after SDK initialization.

Anonymous ID changed

This callback is invoked when the Anonymous ID of the user is changed.

public void onAnonymousIdChanged(Context context, String anonymousUserID);

Callbacks


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.