2012-06-17 26 views
1

我在某些應用程序中看到,當您點擊一個鏈接時,它會詢問您是否要在應用程序中打開它。我見過很多帖子,你可以做Android意圖過濾器mimetype和主機/方案

<intent-filter> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <data android:host="www.ex-ample.com" android:scheme="http" /> 
</intent-filter> 

我還沒有嘗試過,但每篇文章似乎都說它的作品。我試過了:

<intent-filter> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <data android:mimeType="vnd.android.cursor.item/vnd.example.crag" /> 
    <data android:host="www.ex-ample.com" android:scheme="http" /> 
</intent-filter> 

,它似乎沒有工作,我點擊在去www.ex-ample.com/test/123一個文本鏈接,它只是在瀏覽器中打開。

我真的不知道兩件事情:

  1. 可以使用mineType和主機/方案屬性一起
  2. 你可以看到別的問題呢?

回答

3

可以使用mineType和主機/方案是,至少根據the docs on <data>屬性一起

你能看出這個問題嗎?

如果http://www.ex-ample.com/test/123不上的HTTP HEAD請求返回的MIME類型vnd.android.cursor.item/vnd.example.crag的文件,你的<intent-filter>將不匹配。

+0

好....我有點了解。所以我必須將我的網頁的mimetype設置爲vnd.android.cursor.item/vnd.example.crag而不是text/html?你有這樣的例子嗎?這是人們會做的嗎?! –

+0

@matt_lethargic:「所以我必須將我的網頁的mimetype設置爲vnd.android.cursor.item/vnd.example.crag而不是text/html?」 - 如果你想讓它被你的''拾取,是的。 「你有這樣的例子嗎?」 - 這對於維護提供內容的Web服務器或Web應用程序的人來說是個問題。 「這是人們會做的事嗎?!」 - 我懷疑過濾路徑前綴更常見。 – CommonsWare

+0

這組代碼在清單中 將在瀏覽器打開時在我的模擬器中打開應用程序www.ex-ample .com,但不在我的三星S3和HTC一個X。瀏覽器是否會覆蓋該功能,並且有我們可以做的事情。 – visista