Links

Push Callbacks

Netmera provides the following push callbacks:
  • Push Register
  • Push Receive
  • Push Open
  • Push Dismiss
  • Push Button Click

Step 1: Implement a Receiver Class

Create a class that extends NetmeraPushBroadcastReceiver and override any callback's method. For instance,
Pay attention to the use of Toast messages in the production environment.

InAppActionCalllback

Kotlin
Java
inner class NGInAppMessageActionCallbacks : NMInAppMessageActionCallbacks {
private val TAG = "sample"
fun onInAppMessageShown(context: Context?, inAppMessage: NetmeraInAppMessage) {
Toast.makeText(
context,
"onInAppMessageShown triggered :: " + inAppMessage.getId(),
Toast.LENGTH_SHORT
).show()
Log.i(TAG, "onInAppMessageShown triggered :: " + inAppMessage.getId())
}
fun onInAppMessageOpen(context: Context?, inAppMessage: NetmeraInAppMessage) {
Toast.makeText(
context,
"onInAppMessageOpen triggered :: " + inAppMessage.getId(),
Toast.LENGTH_SHORT
).show()
Log.i(TAG, "onInAppMessageOpen triggered :: " + inAppMessage.getId())
}
fun onInAppMessageDismissed(context: Context?, inAppMessage: NetmeraInAppMessage) {
Toast.makeText(
context,
"onInAppMessageDismissed triggered :: " + inAppMessage.getId(),
Toast.LENGTH_SHORT
).show()
Log.i(TAG, "onInAppMessageDismissed triggered :: " + inAppMessage.getId())
}
}
In-App Callback:
To activate an in-app callback, you should choose the 'banner' style within the Netmera control panel. It's important to note that selecting the 'pop-up' style will not trigger the callback.
public class NGInAppMessageActionCallbacks implements NMInAppMessageActionCallbacks {
private final String TAG = "sample";
@Override
public void onInAppMessageShown(Context context, NetmeraInAppMessage inAppMessage) {
Toast.makeText(context, "onInAppMessageShown triggered :: "+inAppMessage.getId(), Toast.LENGTH_SHORT).show();
Log.i(TAG,"onInAppMessageShown triggered :: "+inAppMessage.getId());
}
@Override
public void onInAppMessageOpen(Context context, NetmeraInAppMessage inAppMessage) {
Toast.makeText(context, "onInAppMessageOpen triggered :: "+inAppMessage.getId(), Toast.LENGTH_SHORT).show();
Log.i(TAG,"onInAppMessageOpen triggered :: "+inAppMessage.getId());
}
@Override
public void onInAppMessageDismissed(Context context, NetmeraInAppMessage inAppMessage) {
Toast.makeText(context, "onInAppMessageDismissed triggered :: "+inAppMessage.getId(), Toast.LENGTH_SHORT).show();
Log.i(TAG,"onInAppMessageDismissed triggered :: "+inAppMessage.getId());
}
}
In-App Callback:
To activate an in-app callback, you should choose the 'banner' style within the Netmera control panel. It's important to note that selecting the 'pop-up' style will not trigger the callback.

PushActionCalllback

Kotlin
Java
inner class NGPushActionCallbacks : NMPushActionCallbacks {
fun onPushRegister(context: Context?, gcmSenderId: String?, pushToken: String?) {
Log.v("sample", "onPushRegister")
// Example : PushRegisterIdlingResource.registeredToPush();
// Example : EventBus.getDefault().postSticky(new GCMRegistrationEvent(pushToken));
}
fun onPushReceive(
context: Context?,
bundle: Bundle?,
netmeraPushObject: NetmeraPushObject?
) {
Log.v("sample", "onPushReceive")
Example@ EventBus.getDefault().post(PushReceivedEvent(netmeraPushObject))
}
fun onPushOpen(context: Context?, bundle: Bundle?, netmeraPushObject: NetmeraPushObject?) {
Log.v("sample", "onPushOpen")
}
fun onPushDismiss(
context: Context?,
bundle: Bundle?,
netmeraPushObject: NetmeraPushObject?
) {
Log.v("sample", "onPushDismiss")
}
fun onPushButtonClicked(
context: Context?,
bundle: Bundle?,
netmeraPushObject: NetmeraPushObject?
) {
Log.v("sample", "onPushButtonClicked")
}
// ==>For Netmera SDK versions 3.9.1 and above
fun onCarouselObjectSelected(
context: Context?,
bundle: Bundle?,
netmeraPushObject: NetmeraPushObject?,
selectedIndex: Int,
netmeraCarouselObject: NetmeraCarouselObject?
) {
Log.v("sample", "onCarouselObjectSelected")
}
}
public class NGPushActionCallbacks implements NMPushActionCallbacks {
@Override
public void onPushRegister(Context context, String gcmSenderId, String pushToken) {
Log.v("sample", "onPushRegister");
// Example : PushRegisterIdlingResource.registeredToPush();
// Example : EventBus.getDefault().postSticky(new GCMRegistrationEvent(pushToken));
}
@Override
public void onPushReceive(Context context, Bundle bundle, NetmeraPushObject netmeraPushObject) {
Log.v("sample", "onPushReceive");
Example : EventBus.getDefault().post(new PushReceivedEvent(netmeraPushObject));
}
@Override
public void onPushOpen(Context context, Bundle bundle, NetmeraPushObject netmeraPushObject) {
Log.v("sample", "onPushOpen");
}
@Override
public void onPushDismiss(Context context, Bundle bundle, NetmeraPushObject netmeraPushObject) {
Log.v("sample", "onPushDismiss");
}
@Override
public void onPushButtonClicked(Context context, Bundle bundle, NetmeraPushObject netmeraPushObject) {
Log.v("sample", "onPushButtonClicked");
}
@Override // ==>For Netmera SDK versions 3.9.1 and above
public void onCarouselObjectSelected(Context context, Bundle bundle, NetmeraPushObject netmeraPushObject, int selectedIndex, NetmeraCarouselObject netmeraCarouselObject) {
Log.v("sample", "onCarouselObjectSelected");
}
}

Widget Callback Methods

If you want to handle widget-related actions, implement the NMWebWidgetCallbacks interface and override the onDeeplinkTriggered() and onOpenUrlTriggered() methods.
Select Widget Style on Netmera Panel:
To trigger a Widget callback, you must select the "Widget" style when creating the widget in Netmera panel.
Choosing Manage App:
If you want the action to be handled within the application; when assigning an action to an element, choose 'Manage App' on "Create New Widget" on Netmera Panel. Without this selection, the SDK will handle it, but it won't trigger the callback.
Kotlin
Java
inner class NGWebWidgetCallbacks : NMWebWidgetCallbacks {
fun onDeeplinkTriggered(deeplink: String) {
Log.i("NetmeraApp", "Deeplink was triggered and should be handled by app. :: $deeplink")
}
fun onOpenUrlTriggered(url: String) {
Log.i("NetmeraApp", "OpenUrl was triggered and should be handled by app. :: $url")
}
}
public class NGWebWidgetCallbacks implements NMWebWidgetCallbacks {
@Override
public void onDeeplinkTriggered(String deeplink) {
Log.i("NetmeraApp", "Deeplink was triggered and should be handled by app. :: "+deeplink);
}
@Override
public void onOpenUrlTriggered(String url) {
Log.i("NetmeraApp", "OpenUrl was triggered and should be handled by app. :: "+url);
}
@Override
public void onWebWidgetShown(String url) {
Log.i("NetmeraApp", "WebWidget shown :: "+url);
}
@Override
public void onWebWidgetDismiss(String url) {
Log.i("NetmeraApp", "WebWidget dismiss :: "+url);
}
}

Step 2: Let Netmera Know You Use Custom Receiver

To ensure consistency in Netmera's business logic and data collection, add the following line in the defaultConfig block of your Gradle file,
android {
...
defaultConfig {
...
//following line is for using custom push receiver
resValue "bool", "netmera_use_default_push_receiver", "false"
...
}
}