2014-05-03 62 views
1

我試圖在android上攔截我自己的應用程序的URL,以便用戶可以在應用程序而不是瀏覽器中打開URL。 (我還沒有瀏覽器支持)。應用程序不攔截url

這是我在做什麼

<activity android:name=".ui.activity.MainActivity" android:label="@string/app_name"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
    <intent-filter> 
     <action android:name="android.intent.action.PICK_ACTIVITY" /> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
     <data android:scheme="http" /> 
     <data android:host="myapp.com" /> 
     <data android:pathPattern=".*"/> 
    </intent-filter> 
</activity> 

出於某種原因,只要我打開myapp.com它仍保持打開瀏覽器,不給我在我的應用程序打開URL的選項。我正在模擬器上運行API 16。我已經關閉了仿真器幾次並重新開始,但仍然是同樣的行爲。

爲了避免我的個人應用程序的URL中的任何錯誤。我甚至嘗試過:

  <data android:host="goo.gl" android:scheme="http" /> 
     <data android:host="goo.gl" android:scheme="https" /> 

該應用程序攔截上述網址,但只有第一次。如果我在提供的選項中單擊'JUST ONCE',則在重新啓動模擬器之前,我再也沒有選擇該選項。

有沒有人經歷過這個?我可能會做錯什麼?

+0

刪除'安卓pathPattern',因爲你似乎不被使用它,看看是否有幫助。 – CommonsWare

回答

0

這個答案讓我:link to question

如果添加的包名的意圖,它會默認打開應用

+0

按照該URL上的鏈接(http://fokkezb.nl/2013/09/20/url-schemes-for-ios-and-android-2/),我遵循HTTP計劃的建議(頁面底部) 。我沒有看到那個片段和我正在做的事情有什麼不同。 – birdy

+0

我已經放棄了HTTP方案,現在我正在創建自己的方案。這是由我的網站中的JS轉發。但是,在我的應用程序打開後,如何在應用程序中獲取URL?我在這裏問另一個問題:http://stackoverflow.com/questions/23447985/how-to-receive-a-url-from-my-android-app-after-being-forwarded-from-browser – birdy

+0

當你點擊js網站上的鏈接,你的鏈接應該是intent://your.scheme/someotherstuff; package = your.package,這將使手機打開你的應用程序,如果它的安裝,或去谷歌播放,如果它沒有 –