NDEF message with Android HCE

I want to emulate an Android HCE host card. To do this, I extend the HostApduService service class and overwrite the following method:

public byte[] processCommandApdu(byte[] commandApdu, Bundle extras) { if (Arrays.equals(SELECT_APDU, commandApdu)) { NdefMessage message = new NdefMessage(new NdefRecord [] {NdefRecord.createTextRecord("en", "test"}); return message.toByteArray(); } else { return UNKNOWN_CMD_SW; } } 

With the second device, you can receive data from the HCE service. The problem is that I always get a Type A tag, but I need an NDEF message.

Can someone help me?

+1
source share
2 answers

For those who stuck with this issue, I read the NFCForum-TS-Type-4-Tag that @Michael Roland suggested. The whole idea is correct. All you need to do is simulate the SEND and RECEIVED commands to convert an array of bytes into an NDEF message. I created two repositories, one of which encloses the entire package about converting a string to an NDEF message, and the other is the iOS Reader NDEF TAG to check if Android HCE is correct or not.

Good luck

+3
source

Emulating a tag that is defined as an NDEF tag using Android HCE is not as simple as sending an NDEF message in response to a SELECT APDU request. You will need to implement the specification for working with tags such as type 4 of the NFC forum. You can get this specification on the NFC Forum website .

Essentially, you need to register the D2760000850101 service for AID D2760000850101 which implements a couple of APDU commands that the read side uses to access a type 4 tag:

  • SELECT NDEF tag app

     00 A4 04 00 07 D2760000850101 [00] 
  • SELECT container

     00 A4 00 0C 02 E103 
  • SELECT NDEF data file

     00 A4 00 0C 02 xxyy 

    Where xxyy is the identifier of the NDEF data file specified in the capabilities container.

  • READ BINARY (to read data from a capabilities container or NDEF data file, depending on what is currently selected)

     00 B0 xx yy zz 

    Where xx yy is the offset to read, and zz is the number of bytes to read.

Important Note. Please note that such an NFC Forum Type 4 tag emulated by an Android device cannot be used to automatically launch an application on a second Android device (at least unreliable?). Connecting two Android devices usually results in a peer-to-peer connection (even if Beam is turned off!). Only the foreground application on the second Android device can use the NFC Reader mode API to bypass Android Beam and reliably detect the emulated tag.

+2
source

Source: https://habr.com/ru/post/1269596/


All Articles