Android应用程序的深层链接

时间:2015-11-02 12:52:10

标签: android android-intent deep-linking

我需要深层链接我的Android应用程序,我已经搜索了很多并尝试了各种SDK。我希望我给在浏览器本身打开网址的用户提供网址(简短网址)。在浏览器中打开网址后,它应该重定向到应用程序(如果已安装)或重定向到Play商店。我试过“intent:// view?#Intent; package = my.app.id; scheme = myapp; end;”在windows.location的页面上,但它永远不会重定向到我的任何地方。如果我点击该页面上的按钮并且功能明智,它工作正常,我能够做到这一点,但我希望减少用户的点击,当网址被打开时,它会自动重定向他/她。

1 个答案:

答案 0 :(得分:0)

实现从浏览器自动打开深层链接有不同的策略......不幸的是,没有任何方法可以在任何地方使用......

最常见的是尝试导航到深层链接并在一段时间后回到应用商店:

<script>
  // when the page is loaded...
  window.onload = function() {

    // and viewed on an Android Phone...
    if (navigator.userAgent.match(/Android/)) {

      // then try to open the deep link
      window.location.replace('myapp://foo');

      // if it didn't work after half a second, then redirect the
      // user to the app store where he can download the app
      setTimeout(function() {
        window.location.replace('http://play.google.com/store/apps/details?id=com.myapp');
      }, 500);
    }
  }
</script>

适用于Android旧版浏览器和大多数网络视图......

对于Chrome,您必须使用intent://网址。要使其正常工作,您必须在直接用户输入后导航:这意味着您无法在intent://回调中自动加载window.onload网址。实现它的最简单方法是从服务器重定向到intent://网址:

# This example assumes a Ruby on Rails app
def show
  if request.user_agent.match /Android/
    redirect_to 'intent://...'
  else
    render # render your website normally
  end
end

有关更深入的信息,请阅读Google Chrome工程师撰写的此博文:Deep App Linking on Android and Chrome

如果您不想自己处理所有这些问题,那么您可以使用提供深层链接的第三方服务,例如: branch.ioShortcut Media(免责声明:我目前在Shortcut Media工作)。