Johanna previously owned all Branch content including whitepapers, blog posts, and social media, and coordinated North America webinars. She also moonlighted in the product marketing realm, having owned the product update email, written product blog posts, and helped out with landing pages.
Jun 02, 2021
Opening an installed app from a browser is known as “deep linking”, and with this guide you’ll learn how to deep link into your Android app from the mobile web. We’ll focus exclusively on how to trigger an app open from a website page, rather than from the click of a link inside other apps.
Android is, by far, one of the most fragmented platforms that developers have ever had to manage, due to Google’s decision to force device manufacturers to be responsible for porting the OS, which requires backwards compatibility and support of a multitude of devices. In this ecosystem, we, the app developers, are left to pick up the pieces. Deep linking on Android is unfortunately no different— over the years, we’ve seen a plethora of technical requirements that must be used depending on the circumstance and context of the user.
Note that Branch will implement all of this complexity for you, host the deep links, and even give you robust analytics behind clicks, app opens, and down funnel events. You can play around with Branch links for free by signing up here. We highly recommend using our tools instead of trying to rebuild them from scratch, since building deep links is incredibly complicated.
Android App Links are Android’s solution to take users to specific in-app content. They allow your users to bypass the disambiguation dialogue where they select if they want to see content on the mobile web or in the app, such as in the following image:
App Links use HTTP URLs associated with your website domain, and allow a specific app to be the default owner of a given type of link. This ensures that no other app can use your links for deep linking. Note that with App Links, users who do not have your app installed will be taken to your mobile website. Therefore, for the best user experience, configure your mobile website to handle your App Link to prevent users from viewing a 404 page.
To link to your app content, create an intent filter with the following elements and attribute values to be used in your Activity tag within your manifest:
Here’s an example of an intent filter within a manifest for deep linking, using the URI “https://www.example.com/gizmos” :
<intent-filter android:label="@string/filter_view_http_gizmos"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- Accepts URIs that begin with "http://www.example.com/gizmos” --> <data android:scheme="https" android:host="www.example.com" android:pathPrefix="/gizmos" /> <!-- note that the leading "/" is required for pathPrefix--> </intent-filter>
Note that you can use http but then add the network configuration XML file with cleartextTrafficPermitted=true. More information here.
Adding intent filters with URIs for activity content to your app manifest allows Android to route any Intent that has matching URIs to your app.
Use data from your intent to determine the content to show your users. Call the getData() and getAction() methods to retrieve the data and action associated with the incoming intent.
Here’s a code snippet showing how to retrieve data from an intent in Java:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent intent = getIntent(); String action = intent.getAction(); Uri data = intent.getData(); }
You must verify ownership of both your app and your website in order to deep link your users to your app content. Follow these steps:
This will ask the Android system to verify that your app belongs to the URL domain used in your intent filters.
Set android:autoVerify=”true” in any one of the web URL intent filters in your app manifest that include the android.intent.action.VIEW intent action and android.intent.category.BROWSABLE intent category.
To indicate the Android apps associated with your website and app URL intents, start by publishing a Digital Asset Links JSON file at https://domain.name/.well-known/assetlinks.json.
You’ll need the following information to publish the Digital Asset Links JSON file:
$ keytool -list -v -keystore my-release-key.keystore
Make sure that your assetlinks.json file is:
Finally, confirm that the Digital Asset Links JSON file is properly hosted and defined by using the Digital Asset Links API.
After verifying the websites associated with your app and ensuring that the hosted JSON file is valid, install the app on your device. Wait at least 20 seconds for the asynchronous verification process to complete. Use the following command to check whether the system verified your app and set the correct link handling policies:
adb shell am start -a android.intent.action.VIEW \ -c android.intent.category.BROWSABLE \ -d "http://domain.name:optional_port"
You can also review a list of the links handled by all your apps with the following command:
adb shell dumpsys package domain-preferred-apps
And you’re done! That being said, deep linking on Android is incredibly complicated, and there are edge cases everywhere. You’ll think everything is going well until you come across unique edge cases and broken links. That’s why you should use a tool like Branch — to save you from that nightmare and ensure that your links work everywhere. Contact us to discover how you can implement deep links that transform your user experience, reduce churn, and increase ROI.
Johanna previously owned all Branch content including whitepapers, blog posts, and social media, and coordinated North America webinars. She also moonlighted in the product marketing realm, having owned the product update email, written product blog posts, and helped out with landing pages.
Jun 02, 2021