Use NFC device as NFC tag

≡放荡痞女 提交于 2019-12-05 20:52:36
Michael Roland

Depending on your NFC device, this may be possible. However, I do not agree with kamituel that this is being done by multiple applications through Android Beam.

Android Beam uses NFC's peer-to-peer mode which (while it may have a similar effect) is not the same as using one device as a reader (reader/writer mode) and one device as a tag. Peer-to-peer mode uses a different protocol stack for communication than reader/writer mode. I.e. NDEF on top of SNEP on top of LLCP for peer-to-peer mode communication and NDEF on top of one of the Tag Operation specifications for reader/writer mode accessing NFC tags.

So only the data presentation layer (NDEF) is the same for both protocol stacks. In an NFC environment, the NDEF (NFC data exchange format) abstracts the actual communication part and could potentially make applications independed of the used data transport. Android just somewhat failed to make this usable by introducing their Beam UI.

If the NFC device that you want to emulate a tag with is an Android device, you have some requirements and limitations when it comes to emulating an NFC tag:

  • The emulating device needs to run Android 4.4 or later.
  • The emulating device needs to support host-based card emulation. This is not the case for many devices with NXP's PN544 NFC controller.
  • You can only emulate an NFC tag according to the NFC Forum Type 4 Tag Operation specification. This is due to a limitation in Android HCE that only permits emulation of ISO/IEC 7816-4 appliction structures on top of ISO/IEC 14443-4.

In parallel to the HCE capabilities an Android device will also announce its peer-to-peer mode capabilities to other devices. As a consequence, if you want to access an Android HCE emulated NFC tag with another Android device, this other Android device will instead see the peer-to-peer mode capabilities and won't automatically process NDEF messages from the emulated tag.

In order to overcome this limitation, the reading Android device would also need to have Android 4.4 or later. Starting with that platform version, you can disable peer-to-peer mode discovery by using the reader mode API. Only when you do that, you can access the emulated NFC tag from the second Android device.

Yes, it is possible. This is being done by multiple applications. One example is a browser app, which will cause the peer device to open the same page. By doing that, browser causes the peer device to behave virtually the same way as when reading the passive NFC tag.

The key is to send the valid NDEF record to the peer device. For instance, to make a peer device open a browser with the given URL, you could use the following record:

  • TNF: well known (0x01, according to [1])
  • type: 'U' - (0x55, according to [2])
  • payload: URL - usually UTF-8 encoded, with possible abbreviation (see [2] for description)
  • id: null (you might put some value here, but it's not necessary)

You can see that values of the NDEF record fields vary depending on what content you want to serve. The well known ones are URI's (as shown above), text records, smart posters etc.

See NdefRecord class for reference.

[1] NFCForum-TS-NDEF_1.0

[2] NFCForum-TS-RTD_URI_1.0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!