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


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.

PushActionCalllback


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")
    }
}

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.


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")
    }
}

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"
      ...
    }
}

Last updated