2015-11-02 92 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工作)。

相關問題