title: How to fall back to marketplace when Android custom URL scheme not handled?
body: <p>We have an app that handles a custom URL scheme (vstream://).  When someone comes to a web page that has some vstream:// content, we need to redirect them to the store if they don't have our app installed.</p>
  
  <p>In iOS, we do this:</p>
  
  <pre><code>setTimeout(function() {
    window.location =
      "itms://itunes.apple.com/us/app/kaon-v-stream/id378890806?mt=8&amp;uo=4";
  }, 25);
  
  window.location = "vstream:view?code=...stuff...";
  </code></pre>
  
  <p>If the <code>window.location</code> assignment fails, the timeout jumps over the App Store before the dialog box comes up.  (I found this technique here: <a href="https://stackoverflow.com/questions/1108693">Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?</a> .)</p>
  
  <p>Unfortunately, this trick is not working in Android.  We detect the device server side and wrote this instead of the itms: line:</p>
  
  <pre><code>"market://details?id=com.kaon.android.vstream";
  </code></pre>
  
  <p>Trouble is, whereas iOS throws an error when you go to an unhandled url scheme, Android goes to a generated page.  Therefore, the timeout never gets a chance to run.</p>
  
  <p>Is there some way on a web page to explicitly test for whether a custom URL scheme is handled, or can someone suggest a hack like this one that will work in Android?  (Of course, I suppose I need a hack that's going to work no matter what browser they are using, which is probably a tall order...)</p>
  
  <p>UPDATE:
  The approaches below do not work in Jelly Bean on a Nexus 7. The new Chrome browser does not go to a generated page (so the iFrame is not needed), but there does not appear to be any way to know whether the URL scheme was handled. If it was, the timeout fires anyway. If it wasn't handled the timeout fires. If I use an onload handler and an iframe, the onload handler never fires (whether the app is installed or not). I'll update if I ever figure out how to know whether the scheme was handled...</p>
  
  <p>I've removed my "Solved" on my previous solution, since it doesn't work any more.</p>
  
  <p>UPDATE 2:
  I have a good cross-platform solution now that works on iOS, Android 4.1 with Chrome, and Android pre-Chrome. See below...</p>
  
  <p>Update 3:
  Google broke everything again with intents. Check out the VERY nice solution I've accepted by amit_saxena down there someplace /</p>