Prompt Detail:
In Android, the distinction between Deep Links and App Links is crucial for understanding how Android handles URLs that open in apps and why certain links open directly in an app without showing an "Activity Chooser" dialog.
Deep Links
Deep Links are URLs that point to a specific part of an app. They are used to launch an app from a web link, and they require an intent filter setup in the app's manifest. However, deep links are not exclusively linked to a single app. If multiple apps have registered the same deep link, Android shows an "Activity Chooser" dialog allowing the user to select which app to open the link with.
Example manifest entry for a deep link:
xml<activity android:name=".ExampleActivity">
<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="http"
android:host="www.example.com"
android:pathPrefix="/example" />
</intent-filter>
</activity>
App Links
App Links are a specific type of deep link introduced in Android 6.0 (API level 23) that allow your app to take ownership of a URL domain. This ensures that links to your website open directly in your app, without showing an "Activity Chooser" dialog, as long as your app is verified to handle those URLs. The key difference is the verification process that confirms the app is authorized to handle the domain.
Example manifest entry for an app link:
xml<activity android:name=".ExampleActivity">
<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="www.example.com"
android:pathPrefix="/example" />
</intent-filter>
</activity>
android:autoVerify="true"
tells the system to attempt to verify the ownership of the URL domain.
Verification Process
When a user installs your app, Android checks all URLs in intent filters that have autoVerify=true
. The app must prove ownership of these URLs through a file hosted on the domain. This file (assetlinks.json
) contains digital asset links that tie URLs to an app's package name and its certificate. If the verification passes, these URLs are directly opened in your app without showing an "Activity Chooser."
Handling Multiple Apps
If multiple apps on the same device claim to handle the same App Link with successful verification, the user's preference (if set) will dictate the behavior. If there's no preference set, Android may prompt the user to select a default app or show the "Activity Chooser" dialog for those links, depending on the device and OS version.
Conclusion
App Links provide a smoother user experience by ensuring that web links open directly in an app without the ambiguity of an "Activity Chooser," but this requires domain verification to ensure the app is authorized to handle those URLs. Deep Links, while easier to set up, lack this verification, resulting in possible user prompts when multiple apps can handle the same URL. This design helps maintain a balance between user control and convenience, enhancing the user experience by directing links to the intended app while preventing potential misuse by unauthorized apps.