What is the assetlinks.json file for, when using Android deep links?

Krumelur picture Krumelur · May 26, 2017 · Viewed 9.4k times · Source

I'm trying to get deep links to work in my app.

From what I read here, it is enough to add an Intent filter to the app. I tried that and it works fine:

  <intent-filter>
        <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="http"
               android:host="www.example.com"
               android:pathPrefix="/gizmos" />
     </intent-filter>

Reading about "digital asset links" over here, it says:

Website A declares that links to its site should open in a designated app on mobile devices, if the app is installed.

This involves uploading an assetlinks.json to my server.

But I cannot see the benefit of doing this if the intent filter already opens my app, so what is the point?

Answer

CommonsWare picture CommonsWare · May 26, 2017

Quoting from a different piece of documentation:

Android 6.0 (API level 23) and higher allow an app to designate itself as the default handler of a given type of link. If the user doesn't want the app to be the default handler, they can override this behavior from Settings.

Automatic handling of links requires the cooperation of app developers and website owners. A developer must configure their app to declare associations with one or more websites, and to request that the system verify those associations. A website owner must, in turn, provide that verification by publishing a Digital Asset Links file. A Digital Asset Links file is a collection of statements conforming to the Asset Links protocol that make public, verifiable assertions about other apps or websites.

Right now, with your <intent-filter>, if the user clicks on a link to http://www.example.com/gizmos, they should see a chooser, offering to view that content in your app, available Web browsers, etc. With assetlinks.json, on Android 6.0+, you can prove ownership over that domain, and that will cause Android to (by default) bypass the chooser and drive straight to your app.