【问题标题】:NFC NDEF MIME TYPE text/htmlNFC NDEF MIME TYPE 文本/html
【发布时间】:2014-04-16 11:35:46
【问题描述】:

我正在尝试在 NFC 标签上存储一个非常小的 (1K) 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>

我是不是做错了什么?

谢谢!

【问题讨论】:

    标签: android nfc ndef


    【解决方案1】:

    您需要将记录创建为 URI。如:

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

    【讨论】:

    • 我需要将 HTML 页面存储在标签本身上,在我的用户案例中,我可以假设用户没有互联网。
    【解决方案2】:

    嗯..

    显然不可能,清单指定了这个:

    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>
    

    这太严格了。难怪二维码胜过 NFC。

    如果您也这么认为,请为我的功能请求投票!

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

    【讨论】:

      猜你喜欢
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 2020-02-16
      • 2020-06-22
      • 2014-12-01
      • 1970-01-01
      • 2021-06-11
      • 2012-05-10
      相关资源
      最近更新 更多