Deeplinks on Android

Deeplinks on Android as we have implemented on Farechoice

The Deeplinks for the Android app are used to open our Demand Partner's app from sms or email received after a booking confirmation.

📘

Let's use the example of Farechoice, Karhoo's internal app.

  • Open an app from a google research from going to www.google.com and searching for Farechoice and clicking the first link https://farechoice.taxi.
  • If you use Google Chrome as mobile browser, the app should start when clicking the link.
  • If you use Samsung Internet, a small Farechoice icon will be displayed on top to show you the link has an app and you can tap on it to start.

How to make it work

The Android app responds to those web intents by having in AndroidManifest some intent filters as the code below shows.

       <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="http" />
                <data android:scheme="https" />
                <data
                    android:host="@string/kh_deep_link_host"
                    android:pathPrefix="/en-gb/track" />
            </intent-filter>

			<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="http" />
            <data android:scheme="https" />
            <data
                android:host="farechoice.taxi"
                android:pathPrefix="/" />
        </intent-filter>

        <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="android_app"
                android:host="com.karhoo.farechoice"
                android:path="/" />
        </intent-filter>

Here we can see three intent filters that listen for different web intents.

  • The first one is used for deep linking the SMS and Emails,
  • The second one is used for Google Search
  • The third one is used for Android 12 onwards for everything.

📘

It is very important to know that after Android 12, we have some new regulations regarding the deeplinks. By that, we understand that the android:scheme data tag should be explicitly called on its own, not as it was previous in the same data tag as the host and path. Another thing to look for is the android:autoVerify=”true" attribute that should be present now to tell the system to self-check for the assetlinks on the domain.

For A12 we now have to add a file called assetlinks.json to our domain page in the specific path https://farechoice.taxi/.well-known/assetlinks.json. The autoVerify tag will make the system check for us if the assetlinks is present on the registered domain and also if the file contains our app’s SHA256 signature.

An example of the file may be:

[\[  
   {  
      "relation":\[  
         "delegate_permission/common.handle_all_urls"  
      \],  
      "target":{  
         "namespace":"android_app",  
         "package_name":"com.karhoo.farechoice",  
         "sha256_cert_fingerprints":\[  
            "43:A0:49:10:62:B9:5E:75:4C:40:42:1C:62:1E:CE:7A:91:7C:01:E2:15:98:2B:6D:34:CD:A9:61:F5:EF:55:CB"  
         \]  
      }  
   },  
   {  
      "relation": \["delegate_permission/common.handle_all_urls"\],  
      "target": {  
        "namespace": "android_app",  
        "package_name": "com.karhoo.farechoice",  
        "sha256_cert_fingerprints":  
        \["AA:F1:0E:73:9D:17:5C:D0:86:21:98:35:10:0F:1D:2D:C7:EB:71:03:82:4C:8F:07:84:EB:CC:E7:C5:83:65:19"\]  
      }  
   },  
   {  
      "relation":\[  
         "delegate_permission/common.handle_all_urls"  
      \],  
      "target":{  
         "namespace":"android_app",  
         "package_name":"com.karhoo.farechoice",  
         "sha256_cert_fingerprints":\[  
            "75:D9:37:0F:FB:8B:AF:0A:67:25:1E:3D:B7:CB:78:1A:AA:83:A7:FE:5E:6C:C4:DA:B4:AE:F7:A6:5D:41:8D:8F"  
         \]  
      }  
   },  
   {  
      "relation":\[  
         "delegate_permission/common.get_login_creds"  
      \],  
      "target":{  
         "namespace":"web",  
         "site":"https://farechoice.taxi"  
      }  
   },  
   {  
      "relation":\[  
         "delegate_permission/common.get_login_creds"  
      \],  
      "target":{  
         "namespace":"android_app",  
         "package_name":"com.karhoo.farechoice",  
         "sha256_cert_fingerprints":\[  
            "75:D9:37:0F:FC:8B:AD:0A:67:25:1E:3F:B7:CB:7D:1A:AA:83:A7:FE:5B:6A:C4:DA:B4:AE:F7:A6:5D:41:8D:8F"  
         \]  
      }  
   }  
\]](https://farechoice.taxi)\`

Watch out for some small rules for this file:

  1. Always check the file in a JSON parser to have a full working json because every small error will make the app not starting
  2. Always check for duplicated SHA’s, you are not allowed to have a SHA twice or more.

Testing

There are two ways to test the deeplinks:

  1. Go on Google on Chrome. Search for your app (or Farechoice). Select your website link from the results. If you have your app (or Farechoice) installed, it should open right away.
  2. Send yourself an SMS with the content “https://your_traveler_booker_domain/track/follow_code)" which is almost the link for production booking process but without the specific booking tag. Open the SMS on the device and click on the link. The app should open.