【问题标题】:How to write two types of information into nfc tag and make reader read them at the same time?如何将两种信息写入nfc标签并让阅读器同时读取它们?
【发布时间】:2019-08-30 03:21:54
【问题描述】:

我正在从事一个移动编程项目。 Mobile 程序旨在将 uri 信息(如 http://example.com)写入 uri 有效负载和 wifi 凭据,以便当您点击 nfc 标签时,您可以连接到 wifi 并在浏览器中打开 uri。

我已经测试过将两个信息写入一个nfc标签,但它似乎不能同时提供两个操作。

如果项目在点击 nfc 标签时成功,则手机必须弹出 wifi 连接并在浏览器中打开 uri。 如果有人有线索,我会很高兴跟随!

【问题讨论】:

    标签: android uri wifi nfc ndef


    【解决方案1】:

    NDEF 消息由 NDEF 记录组成。在这种情况下,消息应包含 4 条记录,即:

    1. URI 记录类型代表http://example.com
    2. 推荐操作记录
    3. 标题记录
    4. Wifi Simple C配置记录由Wi-FiA联盟 Mime 类型为 application/vnd.wfa.wsc (Android Code that writes such record)

    由前 3 条记录组成的 NDEF 消息如下。请自行更新以包含第 4 条记录。
    ---------- Offset Content Length Explanation 0 0xD1 1 NDEF header. TNF = 0x01(Well Known Type). SR=1, MB=1, ME=1 1 0x02 1 Record name length (2 bytes) 2 0x30 1 Length of the Smart Poster data (48 bytes) 3 “Sp” 2 The record name 5 0x81 1 NDEF header. TNF = 0x01, SR=0, MB=1, ME=0 6 0x01 1 Record name length (1 byte) 7 0x00, 0x00, 0x00, 0x0C 4 The length of the URI payload (12 bytes) (long format) 11 “U” 1 Record type: “U” 12 0x03 1 Abbreviation: “http://” 13 “example.com” 11 The URI itself. 24 0x11 1 NDEF record header (SR=1, TNF=0x01) 25 0x03 1 The length of the record name 26 0x01 1 The length of the “act” payload. 27 “act” 3 Record type: “act” 30 0x00 1 Action = Launch browser 31 0x11 1 NDEF record header (SR=1, TNF=0x01) 32 0x01 1 Length of the record name 33 0x12 1 Length of the record payload (18 bytes) 34 “T” 1 Record type: “T” (=Text) 35 0x05 1 Status byte for the Text (UTF-8, five-byte code) 36 “en-US” 5 ISO Language code: US-English 41 “Hello, world” 12 The text: “Hello world”, encoded in UTF-8. ----------

    要回答您是否可以让 Android 阅读器处理这些多条记录的问题,我们应该查看NFC Tag Dispatch system
    该系统通过
    创建意图 - 动作 = NfcAdapter.ACTION_NDEF_DISCOVERED
    - MimeType = 第一条记录的 mimetype
    - Intent 的额外 NfcAdapter.EXTRA_NDEF_MESSAGES 包含完整的 Ndef 消息
    因此,Android 仅填充第一个记录的 mimetype。
    它留给应用程序或服务来根据需要处理所有 NDEF 记录。

    【讨论】:

    • 感谢您的深入解释!我已经体验过默认情况下没有任何第三方应用程序原生 android nfc 阅读器读取第一个遇到的 mime 类型。我无法让 android 同时读取两种类型的 mimetype,并且很好奇之前是否有人这样做过,因为该项目需要在没有第三方应用程序的情况下这样做!
    猜你喜欢
    • 2022-01-04
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-11
    相关资源
    最近更新 更多