2015-11-02 91 views
0

我需要深入链接我的Android应用程序,我搜索了很多,并尝试过各种SDK的也。我希望我给在浏览器中打开url的用户提供一个url(短url)。在浏览器中打开url之后,它应该重定向到应用程序(如果已安装)或Play商店。我试过了“intent:// view?#Intent; package = my.app.id; scheme = myapp; end;”在与windows.location页面,但它从来没有重定向我的任何地方。如果我点击该页面上的按钮,并且功能明智,它可以正常工作,但我希望减少用户的点击次数,并在打开URL时自动重定向他/她。深入链接的Android应用程序

回答

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:// URL。为了使其正常工作,您必须在直接用户输入之后进行导航:这意味着您无法尝试在window.onload回调中自动加载intent://网址。实现这一目标最简单的方法是从你的服务器重定向到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 

对于更深入的信息由谷歌浏览器的工程师阅读这个博客帖子:Deep App Linking on Android and Chrome

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

相关问题