2011-04-25 74 views
2

我試圖定義一個意圖過濾器,當我收到包含特定網站的URI NDEF消息只會觸發數據。Android的NDEF意圖過濾器與HTTP協議和主機

我有這樣的定義:

 <intent-filter> 
      <action android:name="android.nfc.action.NDEF_DISCOVERED"/> 
      <category android:name="android.intent.category.DEFAULT"/> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <data android:scheme="http" /> 
      <data android:host="ta.bcntouch.com" /> 
     </intent-filter> 

但它不會引發這樣的。我也嘗試過:

  <data android:scheme="http"android:host="ta.bcntouch.com" /> 

沒有運氣。也僅僅是DEFAULT。去除元素將導致它觸發。

可以這樣做嗎?的Android文檔僅示出了使用MIME類型的元件.....

理解任何幫助的例子。

回答

5

這是我最後使用的過濾器,捕捉到了一些特定的已知URL組合。

的「*」在主機領域的開始讓我與測試服務器是在一個子域,或遵循名稱相同的格式進行測試時使用相同的過濾器。

第二(查看)一個捕捉來自網頁的源,電子郵件等相同的URL格式...:

 <intent-filter> 
      <action android:name="android.nfc.action.NDEF_DISCOVERED"/> 
      <category android:name="android.intent.category.DEFAULT"/> 
      <data android:scheme="http" 
        android:host="*ta.bcntouch.com" 
        android:pathPattern="/p/.*" /> 
      <data android:scheme="http" 
        android:host="*ta.bcntouch.com" 
        android:pathPattern="/l/.*" /> 
      <data android:scheme="http" 
        android:host="*ta.bcntouch.com" 
        android:pathPattern="/a.*" /> 
      <data android:scheme="http" 
        android:host="*ta.bcntouch.com" 
        android:pathPattern="/t.*" /> 
     </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:scheme="http" 
        android:host="*ta.bcntouch.com" 
        android:pathPattern="/p/.*" /> 
      <data android:scheme="http" 
        android:host="*ta.bcntouch.com" 
        android:pathPattern="/l/.*" /> 
      <data android:scheme="http" 
        android:host="*ta.bcntouch.com" 
        android:pathPattern="/a.*" /> 
      <data android:scheme="http" 
        android:host="*ta.bcntouch.com" 
        android:pathPattern="/t/.*" /> 
     </intent-filter> 
-1

我已經做了類似的事情,但我認爲你不能使用URI。您需要編寫MIME ndef消息,並使用intent過濾器將自定義MIME類型(如x-myapp/mydemo)分配給您的活動。然後您可以讀取任何內容,例如URL,並觸發Web瀏覽器。

+0

嗨斯文,感謝回答。我意識到我沒有解釋用戶想要的行爲.....告訴我,如果你認爲我可以用你的想法做到這一點:我想推入一個URL與一個NDEF,使NFC手機沒有我的應用程序可以打開如果NFC手機確實有我的應用程序,那麼它可以捕獲NDEF消息(url和/或mime),並在我的應用程序中而不是Web瀏覽器中查看它。 – 2011-05-07 09:03:27

+0

我認爲你不得不決定這兩個中的一個。如果您編寫NDEF網址類型的消息,則無法通過MIME類型將其鏈接到您的應用程序。順便說一下,如果其他人知道該MIME類型,他可以將其註冊爲一個意圖過濾器,並且它再次不起作用。 – 2011-05-10 06:59:42

3

這種形式對我的作品

<data android:scheme="http" android:host="www.domain.com" android:pathPattern=".*" /> 
+1

謝謝,這工作。如果我只是將'android:host'屬性和'android:scheme'屬性一起添加到我的''標記中,我的應用程序就不會被觸發。但是在添加'android:pathPattern'後,我的應用程序通過單擊匹配_scheme_和_host_的url來調用。不幸的是,[android文檔](http://developer.android.com/guide/topics/manifest/data-element.html)中沒有寫入_pathPattern_或_path_屬性是必需的。 – Yves 2013-02-24 22:40:15