Deeplinking

Available in Batch 1.15.0 and higher

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

  • Java
  • Kotlin
//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;
    }
});

The method getFallbackIntent(context) doesn't need to be overrided, by default Batch will use the LAUNCHER activity from your manifest.