Deep Linking in Android
This document describes how to handling deep links with Engage SDK. For information on deep linking with In-App, see Inbox and In-App Action Handling for Android (Mapp Cloud)
Currently, our SDK does not support custom URI deep links. The SDK currently requires a standardized URI to encode the deep link. When enabling deep linking within the mobile app, include the configuration for the project manifest and java function. When the marketer specifies which deep link to use in Mapp Engage, they need to include the syntax APX://open=deeplink.Â
Deeplink:
The client application needs to define activity to receive deep link data. To do so, create a new activity, with the name DeepLinkActivity
and add the following activity tag in the ApplicationManifest.xml
If the client application didn’t define activity to handle deep link intents, an exception android.content.ActivityNotFoundException
will be thrown when trying to open the provided deeplink.
<activity android:name=".DeepLinkActivity">
<intent-filter>
<data android:scheme="apx"/>
<data android:host="deeplink"/>
<action android:name="com.appoxee.VIEW_DEEPLINK"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="${applicationId}" /> //mandatory for Android FCM SDK v6.0.9 and later
</intent-filter>
</activity>
In the DeepLinkActivity, override onCreate
and onNewIntent
methods and call handleIntent
method. Create handleIntent
method like in the example bellow:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getIntent() != null) {
handleIntent(getIntent());
}
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (APX_LAUNCH_DEEPLINK_ACTION.equals(intent.getAction())) {
Uri uri = intent.getData();
finalLink = uri.getQueryParameter("link");
String protocol = uri.getScheme();
String server = uri.getAuthority();
String path = uri.getPath();
String query = uri.getQuery();
String link = uri.getQueryParameter("link");
String messageId = uri.getQueryParameter("message_id");
// use data from deep link to open WebBrowser, another Activity, etc.
}
}
Â
Example for Compose application with ComponentActivity, how can handle DEEPLINK from push message.
class DeepLinkActivity : ComponentActivity() {
private val APX_LAUNCH_DEEPLINK_ACTION = "com.appoxee.VIEW_DEEPLINK"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val data = remember { mutableStateListOf<String>("Test data") }
Body(data = data)
LaunchedEffect(key1 = Unit) {
if (APX_LAUNCH_DEEPLINK_ACTION == intent.action) {
intent.data?.let {
data.clear()
val link = it.getQueryParameter("link") ?: ""
val messageId: String = it.getQueryParameter("message_id") ?: ""
val eventTrigger: String = it.getQueryParameter("event_trigger") ?: ""
data.add(link)
data.add(messageId)
data.add(eventTrigger)
}
}
}
}
}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Body(data: List<String>) {
TestCoopTheme() {
Surface(
modifier = Modifier
.fillMaxSize()
) {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(10.dp),
) {
items(data) {
Text(it)
}
}
}
}
}
The marketer can use the Deep Link parameter in Mapp Engage when defining the Push Notification to enter the URI of the app page.Â
Â