2016-03-10 37 views

回答

2

當在Android瀏覽器中單擊URL時,系統會檢查URL路徑是否與開發人員包含在AndroidManifest.xml中的任意Intent過濾器匹配(與系統上安裝的每個應用程序捆綁在一起的文件)。如果點擊的URL和其中一個意圖過濾器匹配,則會提示用戶處理相關應用程序中的點擊,而不是瀏覽器中的點擊。以下是Google日曆Android應用清單的舊版本的摘錄,其中包含來自其中一個意圖過濾器的相關網址;任何匹配這些路徑並被點擊的URL都將被定向到日曆應用。

<data android:scheme="http" android:host="www.google.com" android:pathPrefix="/calendar/event" /> 
<data android:scheme="https" android:host="www.google.com" android:pathPrefix="/calendar/event" /> 
<data android:scheme="http" android:host="www.google.com" android:pathPattern="/calendar/hosted/.*/event" /> 
<data android:scheme="https" android:host="www.google.com" android:pathPattern="/calendar/hosted/.*/event" /> 

基本上,你只需要鏈接到谷歌定期日曆web應用程序,並確保所提供的路徑相匹配什麼是在谷歌日曆應用意圖過濾指定。然後,用戶可以選擇使用應用程序而不是瀏覽器處理URL(無法強制用戶從我知道的網站在Android中打開應用程序)。

有關Intent過濾器如何在Android上工作的更多信息,請參閱check out this article about Intents from the Android documentation.

相關問題