# Deeplinking

URLs present in notifications and mobile landings/in-app messages are handled by the Batch SDK in the following ways:

* the default implementation by the SDK will automatically create a new intent using `Intent i = new Intent(ACTION_VIEW, deeplink)` with any URL it encounters
* alternatively you can use a `BatchDeeplinkInterceptor` to handle the URL your way

### Add an interceptor

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

```kotlin
//Inside app onCreate() before Batch.setConfig()
Batch.Actions.setDeeplinkInterceptor(object : BatchDeeplinkInterceptor {
    override fun getTaskStackBuilder(
        context: Context,
        deeplink: String
    ): TaskStackBuilder? {
        //Called only on puhs notifcations
        //Allows you to create a activities task stack when a push is clicked
        val stackBuilder: TaskStackBuilder = TaskStackBuilder.create(context)
        stackBuilder.addParentStack(MyAwseomeLauncherActivity::class.java)

        val intent: Intent = Intent(this, MyAwseomeLauncherActivity::class.java)
        stackBuilder.addNextIntent(intent)

        val uri = Uri.parse(deeplink)
        val deeplinkIntent = Intent(ACTION_VIEW, uri)
        deeplinkIntent.putExtra("my_awesome_extra", "deeplink")
        stackBuilder.addNextIntent(deeplinkIntent)

        return stackBuilder
    }

    override fun getIntent(context: Context, deeplink: String): Intent? {
        //Called for notifications and mobile landings/in-app messages
        //Allows you to customize the deeplink intent
        val uri = Uri.parse(deeplink)
        val intent = Intent(ACTION_VIEW, uri)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        intent.putExtra("my_awesome_extra", "deeplink")
        return intent
    }

    override fun getFallbackIntent(context: Context): Intent? {
        //Called for notifications and mobile landings/in-app messages
        //Allows you to create a fallback when a previous task stack builder or intent could not be launched
        val intent = Intent(
            context,
            MyAwesomeLauncherActivity::class.java
        )
        intent.putExtra("batch_deeplink_fallback", true)
        return intent
    }
})
```

{% endtab %}

{% tab title="Java" %}

```java
//Inside app onCreate() before Batch.setConfig()
Batch.Actions.setDeeplinkInterceptor(new BatchDeeplinkInterceptor() {
    @Nullable
    @Override
    public TaskStackBuilder getTaskStackBuilder(@NonNull Context context,
                                                @NonNull String deeplink) {
    	//Called only on puhs notifcations
    	//Allows you to create a activities task stack when a push is clicked
    	TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addParentStack(MyAwseomeLauncherActivity.class);

        Intent intent = new Intent (this, MyAwseomeLauncherActivity.class);
        stackBuilder.addNextIntent(intent);
        
        Uri uri = Uri.parse(deeplink);
        Intent deeplinkIntent = new Intent(ACTION_VIEW, uri);
        deeplinkIntent.putExtra("my_awesome_extra", "deeplink");
        stackBuilder.addNextIntent(deeplinkIntent);
        
        return stackBuilder;
    }

    @Nullable
    @Override
    public Intent getIntent(@NonNull Context context, @NonNull String deeplink) {
    	//Called for notifications and mobile landings/in-app messages
    	//Allows you to customize the deeplink intent
        Uri uri = Uri.parse(deeplink);
        Intent intent = new Intent(ACTION_VIEW, uri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("my_awesome_extra", "deeplink");
        return intent;
    }

    @Nullable
    @Override
    public Intent getFallbackIntent(@NonNull Context context) {
    	//Called for notifications and mobile landings/in-app messages
    	//Allows you to create a fallback when a previous task stack builder or intent could not be launched
        Intent intent = new Intent(context, MyAwesomeLauncherActivity.class);
        intent.putExtra("batch_deeplink_fallback", true);
        return intent;
    }
});
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The method `getFallbackIntent(context)` doesn't need to be overrided, by default Batch will use the LAUNCHER activity from your manifest.
{% endhint %}


---

# Agent Instructions: 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:

```
GET https://doc.batch.com/developer/sdk/android/advanced/deeplinking.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
