Skip to main content

πŸ€– Generate Dynamic Links in Android

This guide covers how to create a Dynamic Link directly from your Android app using the Dynamic Links Builder API.

πŸ›  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

πŸ”Ή Basic implementation​

import com.chottulink.lib.ChottuLink
import com.chottulink.lib.DynamicLink

ChottuLink.createDynamicLink()
.setLink(Uri.parse("https://yourapp.com/content")) // πŸ”— Destination URL
.setDomain("yourapp.chottu.link") // 🌐 Your ChottuLink domain
.build()
.addOnSuccessListener { dynamicLink ->
if (dynamicLink != null && dynamicLink.getUri() != null) {
// βœ… Success: Retrieve and use the short link
String shortUrl = dynamicLink.getUri().toString();
Log.i("MainActivity", "Successfully created dynamic link: " + shortUrl);
} else {
// ❌ Failure: Handle the error Dynamic link object is null or URI is missing
Log.w("MainActivity", "Dynamic link creation succeeded but result was null or had no URI.");
}
}
.addOnFailureListener(e -> {
// ❌ Failure: Handle the error
Log.e("MainActivity", "Failed to create dynamic link", e);
});

πŸ”Έ Advanced implementation​

/// βœ… Import ChottuLink SDK packages
import com.chottulink.lib.ChottuLink;
import com.chottulink.lib.DynamicLink;

ChottuLink.createDynamicLink()
.setLink(Uri.parse("https://yourapp.com/content")) // πŸ”— Destination URL
.setDomain("yourapp.chottu.link") // 🌐 Your ChottuLink domain
.androidBehavior(DynamicLink.BEHAVIOR_APP) // πŸ€– Android behavior
.iosBehavior(DynamicLink.BEHAVIOR_APP) // 🍏 iOS behavior
.setLinkName("linkName") // 🏷️ Identifier for the link
.setUtmSource("email")
.setUtmMedium("newsletter")
.setUtmCampaign("summer2025")
.setUtmContent("banner_email")
.setUtmTerm("best summer sale")
.setSelectedPath("promo-summer") // πŸ“ Custom path in the dynamic link (Optional)
.build()
.addOnSuccessListener(dynamicLink -> {
if (dynamicLink != null && dynamicLink.getUri() != null) {
// βœ… Success: Retrieve and use the short link
String shortUrl = dynamicLink.getUri().toString();
Log.i("MainActivity", "Successfully created dynamic link: " + shortUrl);
} else {
// ❌ Failure: Handle the error Dynamic link object is null or URI is missing
Log.w("MainActivity", "Dynamic link creation succeeded but result was null or had no URI.");
}
})
.addOnFailureListener(e -> {
// ❌ Failure: Handle the error
Log.e("MainActivity", "Failed to create dynamic link", e);
});
tip

Each behavior can be set independently for iOS and Android platforms, allowing for platform-specific user experiences.

Open in App

DynamicLink.BEHAVIOR_APP

How it works

  • Opens the app if installed
  • Redirects to Play Store (Android) or App Store (iOS) if not installed

When to Use .BEHAVIOR_APP

  • App-driven experiences
  • Deep linking to specific content
  • Encouraging app installs

Example

.androidBehavior(DynamicLink.BEHAVIOR_APP)

Always Browser

DynamicLink.BEHAVIOR_BROWSER

How it works

  • Always opens in the browser
  • No redirection to the app or store

When to Use .BEHAVIOR_BROWSER

  • Web-only experiences
  • Marketing campaigns
  • When you don’t want to disrupt the user’s current flow

Example

.androidBehavior(DynamicLink.BEHAVIOR_BROWSER)

πŸ’‘ Best Practices​

  1. Error Handling

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

    • Set appropriate minimum app versions
    • Include fallback URLs
    • Add social media metadata
  3. Testing

    • Test on different Android versions
    • Verify Play Store redirects
    • Check deep linking behavior

βœ… Next Steps​