To utilize the In-App Action Callback, Push Action Callback, and Widget Callbacks, ensure you include the following callback lines during the initialization of the Netmera SDK > Step 5. Initialize Netmera SDK
overridefunonCreate() {super.onCreate()val configBuilder = NetmeraConfiguration.Builder() .apiKey(apiKey) .firebaseSenderId(PropertiesUtil.gcmSenderId) .huaweiSenderId(PropertiesUtil.hmsSenderId) // Init example if you are going to call Huawei services .logging(true) // Allows Netmera logs to appear in logcat .nmInAppMessageActionCallbacks(NGInAppMessageActionCallbacks()) // Set In-App Message Action Callback .nmPushActionCallbacks(NGPushActionCallbacks()) // Set Push Action Callback .nmWebWidgetCallbacks(NGWebWidgetCallbacks()) // Set Web Widget Callback Netmera.init(configBuilder.build(this))}
By adding the following lines, you enable the respective callbacks to handle specific actions for in-app messages, push notifications, and web widgets.
.nmInAppMessageActionCallbacks()
.nmPushActionCallbacks()
.nmWebWidgetCallbacks()
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.
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.
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.
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 Widgetcallback, 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.
innerclassNGWebWidgetCallbacks : NMWebWidgetCallbacks {funonDeeplinkTriggered(deeplink: String) { Log.i("NetmeraApp", "Deeplink was triggered and should be handled by app. :: $deeplink") }funonOpenUrlTriggered(url: String) { Log.i("NetmeraApp", "OpenUrl was triggered and should be handled by app. :: $url") }}
publicclassNGWebWidgetCallbacksimplementsNMWebWidgetCallbacks { @OverridepublicvoidonDeeplinkTriggered(String deeplink) {Log.i("NetmeraApp","Deeplink was triggered and should be handled by app. :: "+deeplink); } @OverridepublicvoidonOpenUrlTriggered(String url) {Log.i("NetmeraApp","OpenUrl was triggered and should be handled by app. :: "+url); } @OverridepublicvoidonWebWidgetShown(String url) {Log.i("NetmeraApp","WebWidget shown :: "+url); } @OverridepublicvoidonWebWidgetDismiss(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"... }}