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 encountersalternatively you can use a
BatchDeeplinkInterceptor
to handle the URL your way
Add an interceptor
//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
}
})
//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.
Last updated
Was this helpful?