Engagement / Push(Old)

Callbacks

Implement you class with PushNotificationCallbacks and register it to WebEngage.

public class MyApplication extends Application {

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

1.Push Notification Received

PushNotificationData onPushNotificationReceived(Context context, PushNotificationData pushNotificationData);

This callback gets triggered before push notification is shown . This is point to where you can make any tweaks or customisation to push notification data received from server.

2.Push Notification Shown

void onPushNotificationShown(Context context, PushNotificationData pushNotificationData);

This callback gets triggered after the notification is shown

3.Push Notification Clicked

boolean onPushNotificationClicked(Context context, PushNotificationData pushNotificationData);

This callback gets triggered when user clicks the notification main intent(i.e primary call to action).
Return true if click was handled else false.

4.Push Notification Action Clicked

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

This callback gets triggered when user clicks the notification non-primary call to action button(if any).
Return true if click was handled else false.

5.Push Notification Dismissed

void onPushNotificationDismissed(Context context, PushNotificationData pushNotificationData);

This callbacks gets triggered when the notification is dismissed either by swiping it away or by clearing system tray.

Sample Implementation

public class PushNotificationCallbacksImpl implements PushNotificationCallbacks {

    private static final String TAG = "PushNotificationCallbacksImpl";

    @Override
    public PushNotificationData onPushNotificationReceived(Context context, PushNotificationData pushNotificationData) {
        Log.d(TAG, "Received Push Notification , Experiment Id : " + pushNotificationData.getExperimentId());
        return pushNotificationData;
    }

    @Override
    public void onPushNotificationShown(Context context, PushNotificationData pushNotificationData) {
        Log.d(TAG, "Push Notification Shown , Experiment Id : " + pushNotificationData.getExperimentId());
    }

    @Override
    public boolean onPushNotificationClicked(Context context, PushNotificationData pushNotificationData) {
        Log.d(TAG, "User clicked Push Notification , Experiment Id : " + pushNotificationData.getExperimentId());
        return false;
    }

    @Override
    public void onPushNotificationDismissed(Context context, PushNotificationData pushNotificationData) {
        Log.d(TAG, "Push notification dismissed , Experiment Id : " + pushNotificationData.getExperimentId());
    }

    @Override
    public boolean onPushNotificationActionClicked(Context context, PushNotificationData pushNotificationData, String buttonId) {
        Log.d(TAG, "User clicked push notification action button , Experiment Id : " + pushNotificationData.getExperimentId() + " button Id : " + buttonId);
        return false;
    }
}


Customising Push Icons and Accent Color

Our SDK uses application icon to set push notification small and large icon. If you want to show your own custom icon then please insert below meta-data tags inside application tag of AndroidManifest.xml file with proper values.

<meta-data
   android:name="com.webengage.sdk.android.small_icon"
   android:resource="@drawable/YOUR_ICON_NAME"/>

<meta-data
   android:name="com.webengage.sdk.android.large_icon"
   android:resource="@drawable/YOUR_ICON_NAME"/>

<meta-data
   android:name="com.webengage.sdk.android.accent_color"
   android:value="#FF0000"/>

The above method will work only from SDK version 1.14.0 and above.

Fixing Notification Icon For Android Lollipop And Above.

Is your small notification icon appearing solid white square?
Since according to android documentation, starting from android lollipop and above, the push small icon must be transparent else it will appear solid white.

So, if you have provided a custom small icon through manifest then please make sure that it is transparent.
If you have not provided a custom small icon then our SDK will continue to use your application icon as a small icon in which case you need to fix your application icon.

Lower Level GCM APIs

Receiving push notification is a straightforward task if GCM Registration and Message Receiving is left to WebEngage.

However, if your application is already configured to handle GCM/FCM, or you intend to do it yourself, WebEngage allows you to do that quite easily too.

You can use our lower level API's to achieve this, and still keep receiving WebEngage Push Notifications along with your existing stuff. Here's how you do it:

1. Passing GCM/FCM Registration Id to WebEngage

After successful registration with GCM/FCM you should pass your registration id to WebEngage using:

WebEngage.get().setRegistrationID(String registrationID)

2. Passing GCM/FCM Messages to WebEngage

All incoming messages from WebEngage will contain a key “source” with the value as “webengage” inside the Android bundle object (both without double-quotes).

You must pass these messages to WebEngage using following api to keep receiving push notifications from WebEngage:

WebEngage.get().receive(Intent intent)

2.1 Passing GCM Messages to WebEngage:

if (data != null && data.containsKey("source") && "webengage".equals(data.getString("source"))) {
            Intent intent = new Intent();
            intent.putExtras(data);//data is the Bundle received
            WebEngage.get().receive(intent);
}

2.2 Passing FCM Messages to WebEngage

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
	Map<String, String> data = remoteMessage.getData();
	if(data != null) {
		if(data.containsKey("source") && "webengage".equals(data.get("source"))) {
			Intent intent = new Intent();
			intent.putExtras(convertMapToBundle(data));
			WebEngage.get().receive(intent);
		}
	}
}

private Bundle convertMapToBundle(Map<String, String> map) {
	Bundle bundle = null;
	if(map != null) {
		bundle = new Bundle();
		for(Map.Entry<String, String> entry : map.entrySet()) {
			bundle.putString(entry.getKey(), entry.getValue());
		}
	}
	return bundle;
}

Messages not containing "source" key, or where "source" is not equal to "webengage" are not required by WebEngage, and can safely be ignored to be passed to WebEngage

Engagement / Push(Old)