App Indexing – Launch Your App via Mobile Browser

Sometimes you might want your app to be launched via a browser on our mobile platform, cause that will provide a better user experience for customers, especially when your website is not RWD ready.

So, how to achieve that goal? Here is the answer.

  1. prepare your domain name, for example, you already have a domain name called, http://www.mydomain.com, and you would have your package name, your.package.name, as well.

  2. You need to modify your AndroidManifest.xml

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:host="www.mydomain.com" android:scheme="http" />
        <data android:host="mydomain.com" android:scheme="http" />
    </intent-filter>

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Please note here, sometimes you might need to add two data fields into your app, cause Android App might not be able to response for only 1 data field. And if you wanna listen to http://www.mydomain.com/some/api/path, you need to add an extra field into AndroidManifest.xml

<data 
    android:host="www.mydomain.com" 
    android:pathPrefix="/some/api/path" 
    android:scheme="http" 
/>

So, now, you can receive browser calling and launch your own app when users click a link in a web page, for example, http://www.mydomain.com/some/api/path. But there’s always a special case here. In scheme field, we listen to HTTP protocol now. But actually, there are two other different ways that you can use, either “intent” or “your own customized scheme“. For intent, Google engineer would suggest developers to use “HTTP” or “intent” (please refer reference 3).

Trade-offs between the two (quotation from stackoverflow):

  • HTTP URIs require you have a domain you own. The user will always get the option to show the URI in the browser. It has very nice fall-back properties where if your app is not installed, they will simply land on your web site.
  • intent URIs require that your app already be installed and only on Android phones. The allow nearly any intent (but always have the BROWSABLE category included and not supporting explicit components). They allow you to direct the launch to only your app without the user having the option of instead going to the browser or any other app.

But, in fact, we also can use our own scheme to launch applications. For example, android:scheme=”my.special.scheme”. That’s also doable.

So, next step, we need to modify the web links as following.

// for intent scheme
<a href="intent://www.mydomain.com#Intent;scheme=http;package=com.your.package;end">Open Application</a>

// for http scheme 
<a href="http://www.mydomain.com">Open Application</a>

That’s it. Happy coding.

Reference:
1. Airbnb DeepLink dispatch
2. StackOverflow Reference1.
3. StackOverflow Reference2 – Google Engineer

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s