22

We have an android app that is launched when the user is redirected to a custom protocol. We want to have the user redirect to the google/play store for the app if it isn't installed on their device.

For iOS we use something like this: Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps? ... however this doesn't work on android.

This is the basic workflow:

  1. user clicks link on our site
  2. user is redirected to customProtocol://site.com?some=params
  3. if the app is installed the device knows what to do when customProtocol:// url is accessed and the app launches ... however if the app isn't installed android just gives a page not available error page; the solution above for iOS doesn't appear to work.

Any thoughts on how we can achieve this on android? Is it just not possible on android?

Community
  • 1
  • 1
rat
  • 2,544
  • 5
  • 21
  • 19

2 Answers2

23

Any thoughts on how we can achieve this on android?

Not with a "custom protocol" (or, more correctly, a "custom scheme"). The pattern on Android is for you to use a URL that you control.

For example, the Barcode Scanner app has the following defined for its main scanning activity:

  <!-- Allow web apps to launch Barcode Scanner by linking to http://zxing.appspot.com/scan. -->
  <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:scheme="http" android:host="zxing.appspot.com" android:path="/scan"/>
  </intent-filter>

Then, any links to http://zxing.appspot.com/scan will do one of two things:

  1. If the link is clicked from a browser on an Android device, and Barcode Scanner is installed, the user can choose between displaying the app or displaying the Web page associated with the link

  2. If the link is clicked anywhere else (Android device without the app, other mobile device, desktop, notebook, etc.), the browser brings up the Web page for that URL, in which you can do whatever you want, including optionally redirecting to the Play Store

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Interesting, so is it correct to say that there is no way to prevent the chooser dialog from being displayed in 1., while supporting the scenario of opening the play store if the app is not installed? – Matthew May 07 '13 at 06:25
  • 1
    @Matthew: Correct. Everything that can handle the URL comes up in the chooser, which will be a browser (or browsers) plus your app. The custom scheme approach avoids this, at the cost of losing #2, and at the cost of possibly colliding with somebody else's custom scheme. – CommonsWare May 07 '13 at 10:32
  • I was just testing this because I'm going to need this functionality myself, but after installing the Barcode Scanner app, when go to http://zxing.appspot.com/scan, it just shows the webpage instead of opening the app. I checked if chrome is set as default app, but it's not. Any tips? – Tim Jun 05 '15 at 13:50
  • 1
    Never mind, [I read here](http://stackoverflow.com/questions/7231085/how-to-fall-back-to-marketplace-when-android-custom-url-scheme-not-handled) that google went ahead and broke it, this no longer seems to work – Tim Jun 05 '15 at 14:02
  • i also checked by installing Scanner app but it's not launching app it shows web page . Is any one have solution for this question please suggest best answer... – user948319 Jan 08 '16 at 06:51
3

You could define a server-side URL that simply redirects to the application page in Google Play, and use that URL in an intent filter to be captured by your application:

  • If your application is installed, the activity for which you define the intent-filter will be opened.
  • If your application is not installed, the intent-filter will not be found and the browser will be opened and the user will be redirected to Google Play (being prompted if they want to open the Play Store or continue in the browser).
Jorge
  • 477
  • 2
  • 6