π€ 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β
- Configure ChottuLink Dashboard
- Set up your project
- Configure Android app settings
- Get your API key
- Install ChottuLink Android SDK
- Initialize ChottuLink Android SDK
π Build a Dynamic Linkβ
πΉ 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);
});
π Link Behaviorsβ
tip
Each behavior can be set independently for iOS and Android platforms, allowing for platform-specific user experiences.
Open in App
DynamicLink.BEHAVIOR_APPHow 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_BROWSERHow 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β
-
Error Handling
- Implement proper error callbacks
- Handle network failures
- Log errors for debugging
-
Link Parameters
- Set appropriate minimum app versions
- Include fallback URLs
- Add social media metadata
-
Testing
- Test on different Android versions
- Verify Play Store redirects
- Check deep linking behavior