App Links, Deep Links, and Intent Filters for seamless app-to-app navigation.
Deep Links vs App Links
# Deep Links
- Custom scheme: myapp://screen/detail/123
- Works on all Android versions
- Can be intercepted by other apps
- No verification required
# App Links (Verified Links)
- HTTPS URLs: https://example.com/detail/123
- Android 6.0+ (API 23+)
- Verified ownership via Digital Asset Links
- Opens directly in app (no disambiguation dialog)
- Higher trust and securityDeep Links Setup
<!-- AndroidManifest.xml -->
<activity android:name=".DetailActivity" android:exported="true">
<!-- Deep link with custom scheme -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" android:host="detail" />
</intent-filter>
<!-- Deep link with path pattern -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="myapp"
android:host="product"
android:pathPrefix="/item/" />
</intent-filter>
</activity>// Handle deep link in Activity
class DetailActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
handleIntent(intent)
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleIntent(intent)
}
private fun handleIntent(intent: Intent) {
val action = intent.action
val data = intent.data
if (Intent.ACTION_VIEW == action && data != null) {
// myapp://detail/123
val itemId = data.getLastPathSegment()
val host = data.host // "detail"
when (host) {
"detail" -> loadDetail(itemId)
"product" -> loadProduct(itemId)
}
}
}
}App Links Setup (Verified)
<!-- AndroidManifest.xml -->
<activity android:name=".DetailActivity" android:exported="true">
<!-- App Link - auto-verified -->
<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" />
<!-- HTTPS scheme required -->
<data android:scheme="https" android:host="example.com" />
<data android:scheme="https" android:host="www.example.com" />
<!-- Path patterns -->
<data android:pathPrefix="/detail/" />
<data android:pathPrefix="/product/" />
<data android:pathPrefix="/user/" />
</intent-filter>
</activity>Digital Asset Links (Assetlinks.json)
// Host at: https://example.com/.well-known/assetlinks.json
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.myapp",
"sha256_cert_fingerprints": [
"14:6D:E9:83:C5:73:06:50:D8:EE:B9:95:2F:34:FC:64:16:A0:83:42:E6:1D:BE:A8:8A:04:96:B2:3F:CF:44:E5"
]
}
}]# Get SHA256 fingerprint
keytool -list -v -keystore release.keystore -alias my-key
# Or for debug
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkeyNavigation with Deep Links
// Compose Navigation with deep links
@Composable
fun AppNavHost(
modifier: Modifier = Modifier,
startDestination: String = "home"
) {
val navController = rememberNavController()
NavHost(navController, startDestination, modifier) {
composable("home") { HomeScreen(onItemClick = { id ->
navController.navigate("detail/$id")
}) }
composable(
route = "detail/{itemId}",
arguments = listOf(navArgument("itemId") { type = NavType.StringType }),
deepLinks = listOf(
navDeepLink { uriPattern = "myapp://detail/{itemId}" },
navDeepLink { uriPattern = "https://example.com/detail/{itemId}" }
)
) { backStackEntry ->
val itemId = backStackEntry.getString()!!
DetailScreen(itemId = itemId)
}
composable(
route = "product/{productId}",
arguments = listOf(navArgument("productId") { type = NavType.StringType }),
deepLinks = listOf(
navDeepLink { uriPattern = "https://example.com/product/{productId}" }
)
) { backStackEntry ->
val productId = backStackEntry.getString()!!
ProductScreen(productId = productId)
}
}
}
// Handle deep link from outside
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Handle intent that launched app
handleDeepLink(intent)
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleDeepLink(intent)
}
private fun handleDeepLink(intent: Intent?) {
intent?.data?.let { uri ->
val navController = findNavController(R.id.nav_host)
val deepLink = navController.createDeepLink()
.setDestination(uri)
.setGraph(R.navigation.nav_graph)
.createPendingIntent()
try {
deepLink.send()
} catch (e: Exception) {
// Fallback
navController.navigate(uri.toString())
}
}
}
}Testing Deep Links
# Test deep link via ADB
adb shell am start -W -a android.intent.action.VIEW -d "myapp://detail/123" com.example.myapp
# Test App Link (requires verification)
adb shell am start -W -a android.intent.action.VIEW -d "https://example.com/detail/123" com.example.myapp
# Verify App Links
adb shell pm verify-app-links --re-verify com.example.myapp
# Check verification status
adb shell pm get-app-links com.example.myapp// Unit test for deep link handling
class DeepLinkTest {
@Test
fun testDetailDeepLink() {
val uri = Uri.parse("myapp://detail/item123")
val intent = Intent(Intent.ACTION_VIEW, uri)
val activity = launchActivity<DetailActivity>(intent)
// Verify detail loaded
onView(withId(R.id.detail_title)).check(matches(withText("Item 123")))
}
@Test
fun testAppLinkNavigation() {
val uri = Uri.parse("https://example.com/detail/item123")
val intent = Intent(Intent.ACTION_VIEW, uri)
val activity = launchActivity<MainActivity>(intent)
// Verify navigation to detail
}
}Dynamic Feature Module Deep Links
// In dynamic feature module
// AndroidManifest.xml
<activity android:name=".FeatureActivity" android:exported="true">
<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" />
<data android:scheme="https" android:host="example.com" android:pathPrefix="/feature/" />
</intent-filter>
</activity>
// Install module and navigate
fun navigateToFeature(navController: NavController, featureId: String) {
SplitInstallManagerFactory.create(context).startInstall(listOf("feature"))
.addOnSuccessListener {
navController.navigate("feature/$featureId")
}
}Universal Links (iOS) / App Links (Android) Parity
// Shared URL patterns for iOS Universal Links and Android App Links
object AppLinks {
// Base domain
const val DOMAIN = "example.com"
// Paths
const val DETAIL_PATH = "/detail/"
const val PRODUCT_PATH = "/product/"
const val USER_PATH = "/user/"
const val SETTINGS_PATH = "/settings/"
// Build URLs
fun detailUrl(id: String) = "https://$DOMAIN$DETAIL_PATH$id"
fun productUrl(id: String) = "https://$DOMAIN$PRODUCT_PATH$id"
fun userUrl(id: String) = "https://$DOMAIN$USER_PATH$id"
// Deep link versions (fallback)
fun detailDeepLink(id: String) = "myapp://detail/$id"
fun productDeepLink(id: String) = "myapp://product/$id"
}Sharing with Deep Links
// Create share intent with deep link
fun createShareIntent(item: Item): Intent {
val url = AppLinks.detailUrl(item.id)
val deepLink = AppLinks.detailDeepLink(item.id)
return Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TITLE, item.name)
putExtra(Intent.EXTRA_TEXT, """
Check out ${item.name}!
$url
""".trimIndent())
// Add deep link as fallback
putExtra("android.intent.extra.STREAM", Uri.parse(deepLink))
}
}
// Receive shared content
class ShareReceiverActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Intent.ACTION_SEND == intent.action && intent.type == "text/plain") {
val sharedText = intent.getStringExtra(Intent.EXTRA_TEXT) ?: ""
// Extract URL from shared text
val url = extractUrl(sharedText)
if (url != null) {
handleDeepLink(Uri.parse(url))
}
}
}
private fun extractUrl(text: String): String? {
val pattern = Pattern.compile("https?://[^\\s]+")
val matcher = pattern.matcher(text)
return if (matcher.find()) matcher.group() else null
}
}App Links Verification
// Check verification status programmatically
class AppLinkVerificationHelper @Inject constructor(
@ApplicationContext private val context: Context
) {
fun checkVerificationStatus(): List<VerificationInfo> {
val packageManager = context.packageManager
val packageName = context.packageName
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
packageManager.getPackageInfo(packageName, PackageManager.GET_INTENT_FILTERS)
.activities?.flatMap { activity ->
activity.intentFilters?.filter { it.hasCategory(Intent.CATEGORY_BROWSABLE) }
?.map { filter ->
VerificationInfo(
host = filter.authorities?.firstOrNull()?.host ?? "",
path = filter.authorities?.firstOrNull()?.path ?? "",
verified = packageManager.getIntentFilterVerificationStatus(
packageName, filter
) == PackageManager.INTENT_FILTER_VERIFIED
)
} ?: emptyList()
} ?: emptyList()
} else {
emptyList()
}
}
fun requestVerification() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val intent = Intent(Settings.ACTION_MANAGE_APP_VERIFICATION)
.setData(Uri.fromParts("package", context.packageName, null))
context.startActivity(intent)
}
}
}
data class VerificationInfo(
val host: String,
val path: String,
val verified: Boolean
)Try It
Add intent filters with android:autoVerify=true. Host assetlinks.json on your domain. Test with ADB. Verify with pm verify-app-links. Handle in Compose Navigation.
# Test:
adb shell am start -W -a android.intent.action.VIEW -d "https://example.com/detail/123" com.example.myapp
adb shell pm verify-app-links --re-verify com.example.myappApp Links mastery
- Add deep link intent filters with custom scheme
- Add App Link intent filters with autoVerify=true
- Host assetlinks.json with correct SHA256
- Handle deep links in Compose Navigation
- Test with ADB commands
- Verify App Link status
- Share content with deep link fallback
- Check verification programmatically
Deep links: custom scheme, works everywhere. App Links: HTTPS, verified ownership, direct open. Require assetlinks.json with package name and SHA256. android:autoVerify="true" in manifest. Test with ADB. Handle in Navigation with navDeepLink.
Resources
- App Links: https://developer.android.com/training/app-links
- Deep Links: https://developer.android.com/training/app-links/deep-linking
- Asset Links: https://developers.google.com/digital-asset-links
- Navigation Deep Links: https://developer.android.com/guide/navigation/navigation-deep-link