How to fall back to marketplace when Android custom URL scheme not handled?

后端 未结 7 486
無奈伤痛
無奈伤痛 2020-12-07 09:47

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 th

7条回答
  •  自闭症患者
    2020-12-07 10:03

    Solved! The trick is to open my app in an IFRAME, instead of setting the location:

    setTimeout(function() {
      window.location =
        "market://details?id=com.kaon.android.vstream";
    }, 1000);
    
    document.write('');
    

    Notice that I increased the timeout to 1000, because Android actually does both actions in every case (not ideal, but not awful), and this larger timeout is needed to make sure that Market doesn't end up being the thing the user sees when I'm already installed.

    (And yes, of course using document.write is so last-century, but I'm old school that way :)

提交回复
热议问题