Android Deep linking: Use the same link for the app and the play store

Adam Matan picture Adam Matan · Feb 26, 2015 · Viewed 54.6k times · Source

I have a website which enables the user to make a search query. The query might take some time to complete (minutes to days), and I would like to enable the user to download an Android app and receive the answer there, by sending an email with a link to the user.

I would like this mechanism to work whether the user has the app installed or not; in other words:

  • If the user has the app it should be opened with deep link that contains an identifier argument.
  • If the user does not have it it should open the play store on the app's page (e.g. https://play.google.com/store/apps/details?id=com.bar.foo&referrer=BlahBlah), let the user install it, and open the app with the identifier argument.

enter image description here

Is there a way to form a link that opens an Android application with an argument, that would work regardless if the app is installed or not?

Answer

Adam Matan picture Adam Matan · Mar 1, 2015

This workaround might work:

  1. At the server side, create a redirect rule to google play. For example, https://www.foo.com/bar/BlahBlah will redirect to https://play.google.com/store/apps/details?id=com.bar.foo&referrer=BlahBlah.

  2. At the app, register the server side link as a deep link:

<data android:scheme="https"
          android:host="www.foo.com"
          android:pathPrefix="/bar" />

Now, if the app is installed, the URL will be caught and the path can be parsed to extract the BlahBlah part. If the app isn't installed pressing the link will redirect the user to the Play store with the referring URL.

enter image description here

Notes:

  • /bar/BlahBlah was converted to &referrer=BlahBlah, because the play store receives a URL argument and the deep link mechanism works with URL paths (as far a I can tell)