Intro to Deep Linking on Android

What is Deep linking?

Deeplinks are a concept that help users navigate between the web and applications. They are basically URLs which navigate users directly to the specific content in applications.

What is Android App Links

On the other hand, Android App Links allow an app to designate itself as the default handler of application domain or URL. Unfortunately It works only on on Android 6.0 (API level 23) and higher.

A Scenario For Deep Links to App Content

When a user clicked URL, the Android system tries each of the following actions, in sequential order, until the request succeeds: [1];

  1. Open the user’s preferred app that can handle the URI, if one is designated.
  2. Open the only available app that can handle the URI.
  3. Allow the user to select an app from a dialog.

How to define intent filters

When we talk about handling how to navigate users directly to specific content in applications, we should think about adding an intent filter in our manifest file. An intent filter should contain the following elements and attribute values;

  1. Define ACTION_VIEW intent action so that the intent filter can be reached from Google Search.
<action android:name="android.intent.action.VIEW" />

2. We should include the BROWSABLE category in order to be accessible from a web browser. We should also have DEFAULT category for responding to implicit intents

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

3. Lastly, We should define one or more <data> tags. Each of these tags represents a URI format that resolves to the activity. The following example represents a simple data tag for dolap.com Android app.

<data
android:host="dolap.com"
android:scheme="https" />

How to read data from incoming intents

When you define your intent filter that can handle specific URLs, the system can start your activity via that intent filter.

Intent intent = getIntent();
Uri data = intent.getData();

What is the difference between deep links and app links?

A deep link is an intent filter system that allows users to directly enter a specific activity in an Android app. However there is an issue about this process. When a user click an URL, it might open a dialog which asks the user to select one of multiple apps handling the given URL.

On the other hand, An Android App Link is a deep link based on your website URL that has been verified to belong to your website. When user clicks that URL, it opens your app.

Verify Android App Links

When we want to implement Android App Links to our app, we need to define intent filters using HTTP URLs. In addition to that, We should declare that we own both the app and URLs.

After defining intent filters, we should verify the relationship between the website. We should put a Digital Asset Links JSON file at the following location:

https://domain.name/.well-known/assetlinks.json

How we solved in our Android application Dolap.com

When we started to develop our Android application for Dolap.com, we didn’t have a website. We have launched our application as a mobile first approach. As time goes by, we have build a website that can only list our members products.

We had to handle deep link mechanism for our application so that we started to think about the process. Our scenario was like when an user click a URL that includes dolap.com domain, We should tell the Android system that we can handle the given URL, and navigate to user directly to application.

We have designed an API for our application -including both Android and iOS-. When we get the given URL from bundle in the DeepLinkHandlerActivity, we instantly make API call to our backend service including given URL, wait for the result. The result contains about information how to navigate users in our application. We follow the Chain of Responsibility Design Pattern to make easy implementation.

public interface DeeplinkHandler {

boolean isSatisfiedBy(DeepLinkData data);

void execute(Context context, DeepLinkData data);
}

For example, When user click on a link that contains detail information a random product, we get a productID result from our backend service, use that productID to navigate ProductDetailActivity.

    @Override
public boolean isSatisfiedBy(DeepLinkData data) {
return data.hasProduct();
}

@Override
public void execute(Context context, DeepLinkData data) {
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}