How to handle deep links in Android
Deep links let a person tap a URL and move straight to a useful screen, such as an order, article or event listing. On Android, this may involve an HTTPS App Link, an older custom URI scheme or a link that launches the app from a cold state.
A dependable implementation must verify the destination, route the URI without duplicating screens and degrade safely when the app is absent or connectivity is poor. This matters in Australia, where Android has a large consumer market and Google Play is a primary app storefront.
How deep links work
An HTTPS deep link uses a normal web address and can point to a specific path, query parameter or fragment. If the destination app is associated with that domain, Android can open the app while retaining the browser-based fallback for everyone else. On Android 12 and later, an approved App Link normally opens directly; older versions may show a chooser.
Custom schemes, such as myapp://orders/123, are useful for internal navigation but offer weaker protection. Another installed app can register the same scheme, so use HTTPS App Links for public campaigns and customer messages.
Define a small set of stable destinations before writing code. Each URI should identify one resource, define which parameters are optional and lead to a helpful fallback instead of a blank screen or crash.
Configure app links in Android
Declare verified links on the activity that should receive them. The BROWSEABLE category allows a browser to dispatch the URI, while DEFAULT lets the activity handle it without requiring an exact action match.
<activity
android:name=".MainActivity"
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="links.example.com.au" />
</intent-filter>
</activity>
Serve an assetlinks.json file at https://links.example.com.au/.well-known/assetlinks.json. It must name the Android package and SHA-256 certificate fingerprint. With Google Play App Signing, use the app-signing certificate, not the upload-key certificate.
If the domain runs on a DigitalOcean Droplet, place this static file through Nginx or Apache and inspect the virtual host and certificate over SSH. phpMyAdmin manages MySQL data; it does not publish or verify Android link associations.
Process incoming links in code
Map approved URIs in the navigation graph, then pass the activity intent to the navigation controller. Centralising the mapping keeps email, ads, social posts and in-app buttons on the same route logic.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
navController.handleDeepLink(intent)
}
Override onNewIntent as well, because Android may deliver a second link to an existing activity. Calling setIntent keeps the latest intent available, while handleDeepLink applies any matching navigation-graph destination.
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
navController.handleDeepLink(intent)
}
Parse only the hosts and parameters listed in the route contract. Use URI builder APIs rather than splitting strings, reject malformed values and send unknown destinations to an explanatory page. Record the route in saved state so rotation or process recreation does not replay a purchase or form submission.
Support every app launch state
A cold launch creates the activity and navigation graph from scratch; a warm launch delivers a new intent to an activity already in memory. Handle the intent in both paths, but ensure one incoming link produces one navigation event.
Choose singleTop only when its reuse behaviour matches the screen design. Otherwise, check the current destination and decide whether the link should replace the top screen, open a detail view or create a new task. Blindly appending every URI can fill the back stack with duplicate screens.
If authentication is required, retain the intended destination while the sign-in flow runs. After login, return to that destination only after validating it. When offline, show cached context where possible and make the action resumable rather than claiming the server operation succeeded.
Secure deep-link destinations
Treat every URI as untrusted input, even when it arrives from an email or SMS. Permit only approved HTTPS hosts and paths, and do not let user-controlled parameters become arbitrary redirect targets. Custom schemes need extra scrutiny because another app can claim them.
Do not place access tokens, payment details or unnecessary personal information in a URL. Use short-lived, single-use references for authenticated actions and complete sensitive operations on a verified screen. For a covered Australian business, the Privacy Act 1988 and Australian Privacy Principles govern how personal information is collected, used, secured and retained; the Privacy Act 2024 reforms strengthen this framework.
Commercial messages that use marketing deep links are also subject to the Australian Spam Act 2003. Obtain the required consent, identify the message and provide a working unsubscribe route. Avoid logging full URIs because query strings can contain campaign or user identifiers.
Test links across devices and networks
Test the actual intent filters on hardware, not only in an emulator. Use adb to open a URL, inspect the app’s domain status and force another verification after changing the certificate.
adb shell am start -W -a android.intent.action.VIEW \
-d "https://links.example.com.au/orders/123"
adb shell pm get-app-links com.example.au.app
adb shell pm verify-app-links --re-verify com.example.au.app
Run the matrix with the app installed and uninstalled, signed out and signed in, foreground and background, and with reliable and impaired connections. Include an older supported Android release, Android 12 and a current release, plus a Samsung handset because device-specific prompt behaviour can differ.
Australian conditions deserve explicit checks. Commuters in Sydney and Melbourne may open links while changing apps on public transport, and users outside major metropolitan areas may depend on regional mobile coverage or fixed-wireless services rather than a fast NBN connection. Local formats such as +61 phone numbers and .com.au domains should also be parsed without accidental truncation.
Recommendations for dependable deep links
Use these checks whenever a new campaign, destination or signing setup is introduced:
- Prefer verified HTTPS App Links for public links and reserve custom schemes for controlled internal navigation.
- Publish the certificate fingerprint from the app-signing key and recheck the association file after any key rotation.
- Maintain one route table for manifest filters, navigation destinations, analytics names and fallback pages.
- Exercise cold starts, reconnects, sign-in returns and unknown parameters on physical devices before release.
Create a deep-link test plan for the next Android release and add it to the deployment checklist. On the DigitalOcean Droplet, publish and verify the public association file through the SSH deployment process, then confirm that one real link from an email or SMS opens the intended Australian app screen without a chooser or duplicate destination.