Example of Mobile Deep links for Android app

By | November 2, 2015

In this article we will look at what is Mobile Apps Deep Links in Android App and App indexing. We will consider example of implementation and work of deep links on example of one of our projects.

What is Deep Link and how we can use it?

Deep Linking provides a mechanism to open an application to a specific resource.
In the context of the mobile apps, deep linking consists of using a uniform resource identifier (URI) that links to a specific location within a mobile app, rather than simply launching the app. Deferred Deep Linking allows users to deep link to content, even if the app isn’t already installed. Depending on the mobile device platform, the URI required to trigger the app may be different (from Wikipedia).
fb://profile/120791238003536 is an example of a mobile deep link. When clicked on a webpage opened on smartphone, it should open specific profile in Facebook mobile app.

Given the fact that now the era of mobile technology, this property is very helpful.

Let’s assume we have a mobile website with registration button that should open our mobile app. Link is http://ex-app-host.com/register from Sign Up button, assuming that ex-app-host.com is our domain name.

Deep linking to applications

Deep linking to application

When user clicks on “Sign Up” button in her smartphone (Android in this example), the OS will ask to choose the application to process the request.

Deferred Deep Linking allows users to deep link to content even if the app isn't already installed.

Deferred Deep Linking allows users to deep link to content even if the app isn’t already installed.

How to create Deep Links?

To create Deep Link we need to add <intent-filter> to the Manifest to the activity which will process that link. It may be two kinds of Deep Links: <scheme>://<host><pathprefix> or <scheme>://<host>. In our case, intent-filter would look like this:

<intent-filter>
    <action android:name="android.intent.action.VIEW"></action>
    <category android:name="android.intent.category.DEFAULT"></category>
    <category android:name="android.intent.category.BROWSABLE"></category>
    <!-- Checks URL of this format "ex-app://ex-app-host" -->
    <data android:scheme="ex-app" 
        android:host="ex-app-host"></data>
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.VIEW"></action>
    <category android:name="android.intent.category.DEFAULT"></category>
    <category android:name="android.intent.category.BROWSABLE"></category>
    <!-- Takes a URL starting with "http://ex-app-host.com/register" -->
    <data android:scheme="http"
        android:host="ex-app-host.com"
        android:pathPrefix="/register"></data>
</intent-filter>

Transfer parameters in Deep Links

So, after user clicks on the links, we need to process the parameters. To do this, we need to receive data activity through intent.

In this case, we want to receive the referral code for registration. For example, http://ex-app-host.com/register?ref=234.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recipes);
    onNewIntent(getIntent());
}
protected void onNewIntent(Intent intent) {
    String action = intent.getAction();
    String data = intent.getDataString();
    if (Intent.ACTION_VIEW.equals(action) && data != null) {
        Uri uri=Uri.parse(url_string);
        String inviteCode = uri.getQueryParameter("ref");
        applyInvite(inviteCode);
    }
}

How to test your setup?

To check that you wrote everything correctly, you can use the command line adb:

adb shell am start -a android.intent.action.VIEW -d "http://ex-app-host.com/register?ref=234" com.ex-app
adb shell am start -a android.intent.action.VIEW -d "ex-app://register?ref=345" com.ex-app

After that, our application should start via deep link.

Useful (deep) links

http://developer.android.com/intl/en/training/app-indexing/deep-linking.html
http://developer.android.com/intl/en/training/app-indexing/enabling-app-indexing.html
https://en.wikipedia.org/wiki/Mobile_deep_linking

As always, feel free to contact us for a consultation!

One thought on “Example of Mobile Deep links for Android app

  1. Pingback: Example of Android Mobile Deep links indexing by search engine | DevelopEx blog

Leave a Reply

Your email address will not be published. Required fields are marked *