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
}
})
Last updated
Was this helpful?