Sub topic 2
Custom schemes versus verified HTTPS links
This chapter assumes you can read a URL's parts (scheme, host, path, query) and have built and run a Flutter app on Android and iOS. You don't need any platform setup yet. Later chapters configure each platform in detail. Here you learn the two kinds of links, how they differ, and how to choose between them.
Two ways to address your app
A deep link is a URL that opens a specific screen in your app. The operating system has two mechanisms for deciding which app receives a URL.
- Custom URL schemes use a scheme you invent, such as
com.example.app://products/42. Any app can declare that it handles that scheme. - Verified HTTPS links use a normal web address, such as
https://example.com/products/42. The operating system opens your app only after confirming that the domain owner authorized it. Android calls these App Links. iOS calls them Universal Links.
Flutter treats both the same way once the link reaches the app. The differences are in the operating system's behavior: who may claim the link, what happens when the app is missing, and how much users and other apps trust the link.
Custom schemes
A custom scheme is a registration on the device. Your app tells the system "send me every URL that begins with this scheme."
On Android, you add an intent filter to the main activity in AndroidManifest.xml:
<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="com.example.app" />
</intent-filter>On iOS, you add a URL type to Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>com.example.app</string>
</array>
</dict>
</array>No server is involved. Setup takes a few minutes, which makes custom schemes useful during development.
Weaknesses of custom schemes
- No ownership check. Nothing stops another app from registering the same scheme. On Android, the user may see a chooser listing both apps. On iOS, the system doesn't define which app wins when two apps claim the same scheme. A malicious app can register your scheme and receive links meant for you, including OAuth redirects that carry authorization codes.
- No fallback. If the app isn't installed, the browser can't open the URL. The user sees an error or nothing at all.
- Poor reach. Many email clients, messaging apps, and social apps don't turn a non-HTTP link into something tappable. Search engines and web crawlers ignore them.
- No web equivalent. The same address can't serve a web page, so you can't share one link that works everywhere.
A parsing gotcha
With https://example.com/products/42, the host is example.com. With a custom scheme, the text right after // is also parsed as the host, even though you may think of it as part of the path:
void main() {
final uri = Uri.parse('com.example.app://products/42');
print(uri.scheme); // com.example.app
print(uri.host); // products
print(uri.pathSegments); // [42]
}If your router expects /products/42, a custom-scheme link needs adapting. Some teams write custom links as com.example.app:///products/42 (three slashes, empty host) so the path is the same as in the HTTPS version.
Verified HTTPS links
A verified link starts with a claim from the website. You publish a file on your domain that names your app. The app declares that it wants the domain. The operating system fetches the file and compares the two.
| Platform | App declares | Domain publishes |
|---|---|---|
| Android | Intent filter with `android:autoVerify="true"` | `/.well-known/assetlinks.json` |
| iOS | `applinks:example.com` in Associated Domains | `/.well-known/apple-app-site-association` |
Here is the Android intent filter for https://example.com/products:
<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="/products" />
</intent-filter>The domain-side file pins the package name and the fingerprint of your signing certificate. Another app can't pass verification, because it doesn't have your certificate:
[
{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.example.app",
"sha256_cert_fingerprints": ["<SHA256_FINGERPRINT_OF_SIGNING_CERT>"]
}
}
]On iOS, the equivalent file names your team ID and bundle ID, and lists the paths the app may open:
{
"applinks": {
"details": [
{
"appIDs": ["TEAMID.com.example.app"],
"components": [{ "/": "/products/*" }]
}
]
}
}Later chapters cover these files and the entitlement in detail. For this chapter, the point is that both platforms use a two-sided handshake: the app claims the domain, and the domain claims the app.
What you gain
- Ownership. Only apps the domain names can be the default handler.
- Graceful fallback. If the app isn't installed, or verification fails, the link opens your website in the browser.
- One link everywhere. The same URL works in email, SMS, QR codes, search results, and the web version of your product.
- Direct opening. On a verified link, the user goes straight to the app with no chooser dialog (Android) and no confirmation prompt (iOS).
What it costs
- You need a domain you control and the ability to serve files over HTTPS with no redirects on the well-known paths.
- Android verification depends on the signing certificate. A debug build and a Play-signed release build have different fingerprints, so the file must list every certificate you test with.
- The operating system caches verification results, so fixing a broken file doesn't always take effect immediately.
- Behavior has quirks. On iOS, typing a Universal Link into the Safari address bar doesn't open the app, and a user who chooses to open a link in Safari can cause iOS to remember that choice. On Android, links that fail verification open in the browser instead of showing a chooser on recent versions.
How a tap is resolved
The diagram shows what the system does when a user taps a link in a message.
Choosing between them
For links that users or other people share, use verified HTTPS links. This covers marketing emails, push notification payloads, shared product pages, and QR codes. The fallback to the web and the ownership guarantee are worth the setup.
Custom schemes still have a place:
- Local development. You can test routing before the domain files exist.
- Controlled environments. Examples are enterprise apps on managed devices and links between two apps you publish.
- Legacy integrations. Some third-party services only accept a custom-scheme redirect.
If you must use a custom scheme, pick a unique, reverse-domain name like com.example.app instead of something short like myapp. This reduces collisions but doesn't prevent a deliberate impersonator. Never put secrets or long-lived tokens in a custom-scheme link, and validate everything you receive as untrusted input. Many apps register both types and route them to the same screens, so a single router handles every incoming URL.
Summary of the differences
| Question | Custom scheme | Verified HTTPS link |
|---|---|---|
| Who can claim it? | Any app | Only the app the domain names |
| App not installed? | Fails | Opens the website |
| Needs a server? | No | Yes, with a well-known file |
| Works as a web URL? | No | Yes |
| Setup effort | Minutes | Hours, plus verification debugging |
| Best use | Development, controlled environments | Anything shared with users |
Exercise
A user installs a second app that registers the same custom scheme as yours, myapp://. Name two problems this causes, and explain why a verified HTTPS link avoids them.
Show answer
The second app may receive links meant for yours, which could expose data such as an OAuth authorization code, or the user may be shown a chooser and open the wrong app. A verified HTTPS link avoids both because the operating system opens only apps named in the domain's assetlinks.json or apple-app-site-association file. The second app can't match your package name and signing certificate, or your team ID and bundle ID.
Exercise
What does Uri.parse('com.example.app://orders/7').host return, and how would you write the link so that the path is /orders/7 instead?
Show answer
It returns orders, because the text after // is parsed as the host. Writing the link as com.example.app:///orders/7 gives an empty host and the path /orders/7, which matches the shape of the HTTPS version.