Skip to main content

🤖 Handle App Links in Android

Learn how to implement and handle Dynamic Links in your Android app using the ChottuLink SDK.

🛠 Prerequisites

  1. Configure ChottuLink Dashboard
    • Set up your project
    • Configure Android app settings
    • Get your API key
  2. Install ChottuLink Android SDK
  3. Initialize ChottuLink Android SDK

🔧 Implementation Guide

Add the following to your AndroidManifest.xml:

<activity
android:name=".MainActivity"
android:exported="true">

<!-- ✅ Handle Dynamic Links -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>

<!-- ✅ Replace with your actual domain -->
<data
android:scheme="https"
android:host="yourapp.chottu.link" />
</intent-filter>
</activity>

You should call this method inside the first activity that your app naturally opens (typically right after the splash screen). This should be the same activity where you route users to the correct screen inside your app. Make sure the intent-filter from Step 1 is also defined on this same activity.

import android.util.Log;
import com.chottulink.lib.ChottuLink;
import com.chottulink.lib.DynamicLink; // You'll need this too

// ✅ Handle incoming dynamic link from the app's intent
ChottuLink.getAppLinkData(getIntent()).addOnSuccessListener(new ChottuLink.OnSuccessListener<ChottuLink.AppLinkData>() {
@Override
public void onSuccess(ChottuLink.AppLinkData result) {
if (result != null && result.getLink() != null) {
// ✅ Successfully retrieved the destination link
String link = result.getLink().toString();
Log.i("ChottuLink", "Received link: " + link);

// Tip: ➡️ Navigate to a specific page or take action based on the link


// (OPTIONAL) ➡️Get the deeplink url which was clicked with all the parameters intact. (from SDK v1.1.1+)
// if (result.getShortLinkRaw() != null) {
// Log.d("ChottuLink","ShortLink/Deeplink clicked : "+result.getShortLinkRaw().toString());
// }

} else {
// ❌ No link found in the intent
Log.w("ChottuLink", "No dynamic link found in the intent.");
}
}
});

💡 Best Practices

  1. Error Handling

    • Implement proper error callbacks
    • Handle network failures
    • Log errors for debugging
  2. Link Processing

    • Validate incoming links
    • Handle different link types
    • Implement proper navigation
  3. Testing

    • Test with app installed and not installed
    • Test App Links and custom URL schemes
    • Verify deep linking behavior

URL Processing

Advancedv1.0.6+

Process the shortened Deeplink using the getAppLinkDataFromUri method.
This retrieves the associated app link data and returns a AppLinkData object containing the resolved destination URL and the original short link.

📝 Method Signature

New Feature

This method was introduced in SDK version v1.0.6+

  public static ChottuLinkTask<ChottuLink.AppLinkData> getAppLinkDataFromUri(Uri deeplink)
📥 Parameters
ParameterTypeRequiredDescription
deeplinkUri✅ YesThe shortened URL string to be resolved
📤 Return Value

A AppLinkData object containing:

  public static class AppLinkData {
public final Uri link;
public final Uri shortLink;
}

💻 Basic Implementation

ChottuLink.getAppLinkDataFromUri(Uri.parse("https://yourApp.chottu.link/xxxxxx"))
.addOnSuccessListener(new ChottuLink.OnSuccessListener<ChottuLink.AppLinkData>() {
@Override
public void onSuccess(ChottuLink.AppLinkData result) {
if (result != null) {
if (result.getLink() != null) {
Log.d("ChottuLink","✅ Link : "+result.getLink().toString());
}
if (result.getShortLink() != null) {
Log.d("ChottuLink","✅ Short Link : "+result.getShortLink().toString()); }
}
}
}
})
.addOnFailureListener(new ChottuLink.OnFailureListener() {
@Override
public void onFailure(Exception e) {
Log.e("ChottuLink","❌ Error : "+e.getMessage()); }
}
});

🎯 Use Cases

  • Manual Link Processing: Process links from user input
  • Testing: Test deep link functionality
  • Background Processing: Process links in background tasks
  • Link Validation: Validate links before processing