> For the complete documentation index, see [llms.txt](https://user.netmera.com/netmera-developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://user.netmera.com/netmera-developer-guide/platforms/android/push-notifications/push-callbacks.md).

# Push Callbacks

Register and handle Netmera push, in-app message, web widget, and presentation callbacks.

Netmera SDK sends push, in-app message, and web widget events through callback interfaces. This article shows how to register each callback and handle its events.

All callback interfaces are in the `com.netmera.callbacks` package.

| Interface                       | Setter                                        | Events                                                                          |
| ------------------------------- | --------------------------------------------- | ------------------------------------------------------------------------------- |
| `NMPushActionCallbacks`         | `Netmera.setPushActionCallbacks(...)`         | Push registration, receive, open, dismiss, button click, and carousel selection |
| `NMInAppMessageActionCallbacks` | `Netmera.setInAppMessageActionCallbacks(...)` | In-app message shown, opened, and dismissed                                     |
| `NMWebWidgetCallbacks`          | `Netmera.setWebWidgetCallbacks(...)`          | Web widget shown, dismissed, deeplink, and URL actions                          |
| `NMPushPresentationCallbacks`   | `Netmera.setPushPresentationCallbacks(...)`   | Web view presentation requests                                                  |

### Register callbacks

Register only the callbacks your app needs. Register it in an `Application`, `Activity`, `Fragment`, or another class with the required context.

Each setter replaces the previous instance. Pass `null` to remove a callback.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
class MyApplication : Application() {

    override fun onCreate() {
        super.onCreate()

        Netmera.setPushActionCallbacks(MyPushActionCallbacks())
        Netmera.setInAppMessageActionCallbacks(MyInAppMessageActionCallbacks())
        Netmera.setWebWidgetCallbacks(MyWebWidgetCallbacks())
        Netmera.setPushPresentationCallbacks(MyPushPresentationCallbacks(this))

        Netmera.init(NetmeraParams(apiKey = apiKey, providers = listOf(NMFCMProvider())))
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        Netmera.setPushActionCallbacks(new MyPushActionCallbacks());
        Netmera.setInAppMessageActionCallbacks(new MyInAppMessageActionCallbacks());
        Netmera.setWebWidgetCallbacks(new MyWebWidgetCallbacks());
        Netmera.setPushPresentationCallbacks(new MyPushPresentationCallbacks(this));

        Netmera.init(new NetmeraParams(apiKey, Collections.singletonList(new NMFCMProvider())));
    }
}
```

{% endtab %}
{% endtabs %}

### Scope a callback to a screen

Remove screen-scoped callbacks when the screen stops. This prevents the SDK from retaining a destroyed `Activity` or `Fragment`.

```kotlin
class CampaignActivity : AppCompatActivity() {

    private val inAppCallbacks = object : NMInAppMessageActionCallbacks {
        override fun onInAppMessageShown(context: Context?, inAppMessage: NetmeraInAppMessage) { /* … */ }
        override fun onInAppMessageOpen(context: Context?, inAppMessage: NetmeraInAppMessage) { /* … */ }
        override fun onInAppMessageDismissed(context: Context?, inAppMessage: NetmeraInAppMessage) { /* … */ }
    }

    override fun onStart() {
        super.onStart()
        Netmera.setInAppMessageActionCallbacks(inAppCallbacks)
    }

    override fun onStop() {
        super.onStop()
        Netmera.setInAppMessageActionCallbacks(null)
    }
}
```

{% hint style="info" %}
Avoid `Toast` messages and other UI side effects in production callbacks. Use them only while testing event delivery.
{% endhint %}

### Implement a push action callback

`NMPushActionCallbacks` reports the push notification lifecycle. For non-Netmera messages, `netmeraPushObject` is `null` and `bundle` contains the raw payload.

#### Add the implementation

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
class MyPushActionCallbacks : NMPushActionCallbacks {

    override fun onPushRegister(
        context: Context?, 
        appSenderId: String?, 
        pushToken: String?
    ) {
        Log.v("sample", "onPushRegister :: $pushToken")
    }

    override fun onPushReceive(
        context: Context?,
        bundle: Bundle?,
        netmeraPushObject: NetmeraPushObject?
    ) {
        // netmeraPushObject is null when the message does not come from Netmera
        Log.v("sample", "onPushReceive")
    }

    override fun onPushOpen(
        context: Context?,
        bundle: Bundle?,
        netmeraPushObject: NetmeraPushObject?
    ) {
        Log.v("sample", "onPushOpen")
    }

    override fun onPushDismiss(
        context: Context?,
        bundle: Bundle?,
        netmeraPushObject: NetmeraPushObject?
    ) {
        Log.v("sample", "onPushDismiss")
    }

    override fun onPushButtonClicked(
        context: Context?,
        bundle: Bundle?,
        netmeraPushObject: NetmeraPushObject?
    ) {
        Log.v("sample", "onPushButtonClicked")
    }

    override fun onCarouselObjectSelected(
        context: Context?,
        bundle: Bundle?,
        netmeraPushObject: NetmeraPushObject?,
        selectedIndex: Int,
        netmeraCarouselObject: NetmeraCarouselObject?
    ) {
        Log.v("sample", "onCarouselObjectSelected :: $selectedIndex")
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
public class MyPushActionCallbacks implements NMPushActionCallbacks {

    @Override
    public void onPushRegister(Context context, String appSenderId, String pushToken) {
        Log.v("sample", "onPushRegister :: " + pushToken);
    }

    @Override
    public void onPushReceive(
        Context context,
        Bundle bundle,
        NetmeraPushObject netmeraPushObject
    ) {
        // netmeraPushObject is null when the message does not come from Netmera
        Log.v("sample", "onPushReceive");
    }

    @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
    public void onCarouselObjectSelected(
        Context context,
        Bundle bundle,
        NetmeraPushObject netmeraPushObject,
        int selectedIndex,
        NetmeraCarouselObject netmeraCarouselObject
    ) {
        Log.v("sample", "onCarouselObjectSelected :: " + selectedIndex);
    }
}
```

{% endtab %}
{% endtabs %}

Register the callback:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
Netmera.setPushActionCallbacks(MyPushActionCallbacks())
```

{% endtab %}

{% tab title="Java" %}

```java
Netmera.setPushActionCallbacks(new MyPushActionCallbacks());
```

{% endtab %}
{% endtabs %}

### Implement an in-app message callback

`NMInAppMessageActionCallbacks` reports when an in-app message is shown, opened, or dismissed.

Select the **banner** style in the Netmera Panel. The **pop-up** style does not trigger these callbacks.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
class MyInAppMessageActionCallbacks : NMInAppMessageActionCallbacks {
    private val TAG = "sample"

    override fun onInAppMessageShown(context: Context?, inAppMessage: NetmeraInAppMessage) {
        Log.i(TAG, "onInAppMessageShown triggered :: ${inAppMessage.id}")
    }

    override fun onInAppMessageOpen(context: Context?, inAppMessage: NetmeraInAppMessage) {
        Log.i(TAG, "onInAppMessageOpen triggered :: ${inAppMessage.id}")
    }

    override fun onInAppMessageDismissed(context: Context?, inAppMessage: NetmeraInAppMessage) {
        Log.i(TAG, "onInAppMessageDismissed triggered :: ${inAppMessage.id}")
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
public class MyInAppMessageActionCallbacks implements NMInAppMessageActionCallbacks {

    private final String TAG = "sample";

    @Override
    public void onInAppMessageShown(Context context, NetmeraInAppMessage inAppMessage) {
        Log.i(TAG, "onInAppMessageShown triggered :: " + inAppMessage.getId());
    }

    @Override
    public void onInAppMessageOpen(Context context, NetmeraInAppMessage inAppMessage) {
        Log.i(TAG, "onInAppMessageOpen triggered :: " + inAppMessage.getId());
    }

    @Override
    public void onInAppMessageDismissed(Context context, NetmeraInAppMessage inAppMessage) {
        Log.i(TAG, "onInAppMessageDismissed triggered :: " + inAppMessage.getId());
    }
}
```

{% endtab %}
{% endtabs %}

Register the callback:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
Netmera.setInAppMessageActionCallbacks(MyInAppMessageActionCallbacks())
```

{% endtab %}

{% tab title="Java" %}

```java
Netmera.setInAppMessageActionCallbacks(new MyInAppMessageActionCallbacks());
```

{% endtab %}
{% endtabs %}

### Implement a web widget callback

`NMWebWidgetCallbacks` reports when a web widget is shown or dismissed. It also passes deeplink and URL actions to your app.

{% hint style="info" %}
**Netmera Panel Settings:**

* Select the **Widget** style.
* Select **Manage App** in **Create New Widget** for app-managed actions.
* Otherwise, the SDK handles the action and does not call `onDeeplinkTriggered` or `onOpenUrlTriggered`.
  {% endhint %}

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
class MyWebWidgetCallbacks : NMWebWidgetCallbacks {

    override fun onDeeplinkTriggered(deeplink: String) {
        Log.i("NetmeraApp", "Deeplink was triggered and should be handled by app. :: $deeplink")
    }

    override fun onOpenUrlTriggered(url: String) {
        Log.i("NetmeraApp", "OpenUrl was triggered and should be handled by app. :: $url")
    }

    override fun onWebWidgetShown(url: String) {
        Log.i("NetmeraApp", "WebWidget shown :: $url")
    }

    override fun onWebWidgetDismiss(url: String) {
        Log.i("NetmeraApp", "WebWidget dismiss :: $url")
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
public class MyWebWidgetCallbacks 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);
    }
}
```

{% endtab %}
{% endtabs %}

Register the callback:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
Netmera.setWebWidgetCallbacks(MyWebWidgetCallbacks())
```

{% endtab %}

{% tab title="Java" %}

```java
Netmera.setWebWidgetCallbacks(new MyWebWidgetCallbacks());
```

{% endtab %}
{% endtabs %}

### Implement a push presentation callback

`NMPushPresentationCallbacks` controls web content opened by a push. Use it to present web content in your own UI.

* Return `true` from `presentWebView(push)` after your app starts presentation. The SDK then skips its default web view.
* Return `false` to use the SDK's default web view.
* Use `closeWebView(push)` to dismiss your custom UI after a close request.

For example, instant-show pushes return `false` below. The SDK presents them. Other pushes open `WebViewPopupActivity`.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
class MyPushPresentationCallbacks(
    private val context: Context
) : NMPushPresentationCallbacks {

    override fun presentWebView(push: NetmeraBasePush): Boolean {
        if (push.isInstantShow) {
            return false
        }

        val intent = Intent(context, WebViewPopupActivity::class.java)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        context.startActivity(intent)

        return true
    }

    override fun closeWebView(push: NetmeraBasePush) {
        WebViewPopupActivity.finishCurrent()
    }
}
```

{% endtab %}

{% tab title="Java" %}

```java
public class MyPushPresentationCallbacks implements NMPushPresentationCallbacks {

    private final Context context;

    public MyPushPresentationCallbacks(Context context) {
        this.context = context;
    }

    @Override
    public boolean presentWebView(NetmeraBasePush push) {
        if (push.isInstantShow()) {
            return false;
        }

        Intent intent = new Intent(context, WebViewPopupActivity.class)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);

        return true;
    }

    @Override
    public void closeWebView(NetmeraBasePush push) {
        WebViewPopupActivity.finishCurrent();
    }
}
```

{% endtab %}
{% endtabs %}

### Load the push content

The Activity you open from `presentWebView()` is responsible for loading the push content into its own `WebView`. In `onCreate()`, pass your `WebView` instance to `Netmera.handleWebContent(webView)` — the SDK loads the push's HTML content into it.

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
// 1) Register once in Application.onCreate()
Netmera.setPushPresentationCallbacks(object : NMPushPresentationCallbacks {

    override fun presentWebView(push: NetmeraBasePush): Boolean {
        // Returning false lets the SDK show its default widget.
        val intent = Intent(this@MyApplication, CustomWebViewActivity::class.java)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        startActivity(intent)
        return true // the app is presenting the content
    }

    override fun closeWebView(push: NetmeraBasePush) {
        // The SDK calls this when the "close" action in the content is triggered.
        CustomWebViewActivity.finishCurrent()
    }
})

// 2) Inside CustomWebViewActivity.onCreate()
val webView = findViewById<WebView>(R.id.web_view)
Netmera.handleWebContent(webView) // loads the push content into your WebView
```

{% endtab %}

{% tab title="Java" %}

```java
public class WebViewPopupActivity extends AppCompatActivity {

    private static WebViewPopupActivity currentInstance;

    public static void finishCurrent() {
        if (currentInstance != null) {
            currentInstance.finish();
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view_popup);
        currentInstance = this;

        WebView webView = findViewById(R.id.web_view);
        Netmera.handleWebContent(webView);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (currentInstance == this) {
            currentInstance = null;
        }
    }
}
```

{% endtab %}
{% endtabs %}

Register the callback:

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
Netmera.setPushPresentationCallbacks(MyPushPresentationCallbacks(this))
```

{% endtab %}

{% tab title="Java" %}

```java
Netmera.setPushPresentationCallbacks(new MyPushPresentationCallbacks(this));
```

{% endtab %}
{% endtabs %}

After registration, the SDK delivers the selected events to your callback implementations.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://user.netmera.com/netmera-developer-guide/platforms/android/push-notifications/push-callbacks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
