【问题标题】:Deep Linking of android application安卓应用的深度链接
【发布时间】:2015-11-02 12:52:09
【问题描述】:

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

【问题讨论】:

    标签: android android-intent deep-linking


    【解决方案1】:

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

    最常见的一种是尝试导航到深层链接并在片刻后回退到应用商店:

    <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 旧版浏览器和大多数 webviews...

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

    # 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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-08
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多