How to Open an Android App from the Browser

Johanna Lazar

June 2nd, 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. 

Overview of Android App Links

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.

Steps to Create Android App Links:

1. Create intent filters for incoming links, and define values in your manifest

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:  

  • <action>: To specify the VIEW intent action so that the intent filter can be reached from Google Search.
  • <data> : The <data> tag must include the android:scheme attribute. The data tags represent a URI format that resolves to the activity.
  • BROWSABLE category: required in order for the intent filter to be accessible from a web browser. Without it, clicking a link in a browser cannot route users to your app. 
  • DEFAULT category: to allow your app to respond to implicit intents. 

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.

Branch White Paper
Learn winning mobile finance strategies for user engagement with Branch's Mobile Playbook for the Finance Industry.
Get it now

2. Read data from incoming intents

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();
}

3. Verify ownership of your app and website 

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:

Request automatic app link verification in your manifest. 

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.

Declare the relationship between your website and your intent filters 

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: 

  • package_name: The application ID declared in the app’s build.gradle file.
  • sha256_cert_fingerprints: The SHA256 fingerprints of your app’s signing certificate. You can use the following command to generate the fingerprint via the Java keytool:

$ keytool -list -v -keystore my-release-key.keystore

Make sure that your assetlinks.json file is:

  • served with content-type application/json.
  • accessible over an HTTPS connection, regardless of whether your app’s intent filters declare HTTPS as the data scheme.
  • accessible without any redirects (no 301 or 302 redirects) and accessible by bots (your robots.txt must allow crawling /.well-known/assetlinks.json).
  • published on each domain if your app links supports multiple host domains

Finally, confirm that the Digital Asset Links JSON file is properly hosted and defined by using the Digital Asset Links API.

4. Test URL Intents

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.

Branch provides the leading cross-platform linking and attribution platform, offering solutions that unify user experience and measurement across devices and channels. Branch has been selected by over 75,000 apps since 2014 including Adobe, BuzzFeed, Yelp, and many more, improving experiences for more than 3 billion monthly users across the globe. Learn more about Branch or contact sales today.
Subscribe now for a weekly blog digest containing mobile growth tips, industry updates, and product announcements!