2014-04-16 54 views
0

我試圖在NFC標籤上存儲一個非常小的(1K)html文件。 當通過手機閱讀時,應該觸發瀏覽器打開它。NFC NDEF MIME TYPE text/html

可悲的是我有那些約束:

  • HTML文件(1KB)存儲在標籤上。不只是一個網址。(用戶沒有互聯網)
  • 非text/plain,它應該是text/html。
  • 它應該由默認瀏覽器打開,而不是自定義的定製應用程序。

我創建的標籤是這樣的:

 Tag detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); 
     NdefRecord record = NdefRecord.createMime("text/html", "Hello world in <b>HTML</b> !"); 
     NdefMessage message = new NdefMessage(new NdefRecord[] { record }); 
     if (writeTag(message, detectedTag)) { 
      Toast.makeText(this, "Success: Wrote placeid to nfc tag", Toast.LENGTH_LONG) 
       .show(); 
     } 

但由於某些原因,當讀取標籤,默認的瀏覽器沒有打開。儘管瀏覽器有正確的意圖過濾器:

 <!-- For these schemes where any of these particular MIME types have been supplied, we are a good candidate. --> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.BROWSABLE" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <data android:scheme="http" /> 
      <data android:scheme="https" /> 
      <data android:mimeType="text/html"/> 
      <data android:mimeType="text/plain"/> 
      <data android:mimeType="application/xhtml+xml"/> 
      <data android:mimeType="application/vnd.wap.xhtml+xml"/> 
     </intent-filter> 

難道我做錯了什麼?

謝謝!

回答

0

嗯..

顯然,這是不可能的,清單指定要這樣:

https://android.googlesource.com/platform/packages/apps/Browser/+/ics-mr0/AndroidManifest.xml

<!-- Accept inbound NFC URLs at a low priority --> 
    <intent-filter android:priority="-101"> 
     <action android:name="android.nfc.action.NDEF_DISCOVERED" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <data android:scheme="http" /> 
     <data android:scheme="https" /> 
    </intent-filter> 

這是如此的限制。難怪爲什麼QR碼贏得NFC。

請投我的功能要求,如果你也這麼認爲!

https://code.google.com/p/android/issues/detail?id=68668

0

您需要將記錄創建爲URI。如:

NdefRecord rtdUriRecord1 = NdefRecord.createUri("http://example.com");

+0

我需要的HTML頁面存儲在標籤本身,在我的用戶的情況下,我可以假設用戶沒有上網。 – Taiko