Read NfcV in Android
2024-03-26 02:47

In my App (Android studio java) I'm trying to read a payload from a specific tag with result of type ndefFormatable and NfcV. Once I get the intent and identify the tag by: Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); I then create a NFCV object and do the following operation:

NfcV nfcV = NfcV.get(tag); byte[] data = new byte[0]; byte[] id = tag.getId(); if (nfcV != null) { byte[] infoCmd = new byte[2 + id.length]; // set "addressed" flag infoCmd[0] = 0x20; // Get System Information command byte infoCmd[1] = 0x2B; //adding the tag id System.arraycopy(id, 0, infoCmd, 2, id.length); System.arraycopy(id, 0, infoCmd, 2, 8); try { nfcV.connect(); // infoCmd VALUE: [32, 43, 107, 32, -61, -97, 116, 77, 2, -32] // DATA RESULT: [0, 11, 107, 32, -61, -97, 116, 77, 2, -32, -1, 0, 78] data = nfcV.transceive(infoCmd); } catch (IOException e) { e.printStackTrace(); } finally { try { nfcV.close(); } catch (IOException e) { e.printStackTrace(); } } }

The problem is that the data I receive from the nfc.transceive is not what I expect it to be, I don't know if it is because the content of infoCmd is wrong or simply because like this I cannot get the payload from the device. If it can help I want to clarify that with this exact nfc device, in an other c# code I am able to get the payload with the ProximityDevice Object by:

ProximityMessage message; var rawMsg = message.Data.ToArray();

And I must replicate this exact result (rawMsg) in my Android app, basically I'm trying to get the same payload sent from the same nfc device but in an other app, in this case Android.




other answer :

It seems like youre attempting to read data from an NFCV (NFC Type V) tag in your Android app, but youre encountering issues with the data received from the transceive operation.

When working with NFCV tags, its essential to understand the protocol and commands required to communicate with them effectively. NFCV tags typically follow the ISO 15693 standard, and you need to send the appropriate commands to read data from them.

Heres a breakdown of your code and potential issues:

Constructing the Command: The command youre constructing (infoCmd) seems incorrect. For reading data from an NFCV tag, you typically need to use the "Read Single Block" command (0x20). The command structure usually includes the command byte, followed by the block address you want to read. Refer to the NFCV specification for the correct command structure.

Transceive Operation: After constructing the command, you use the transceive method to send the command to the tag and receive the response. Ensure that the command youre sending is correct according to the NFCV protocol.

Heres a corrected version of your code:

javaNfcV nfcV = NfcV.get(tag); byte[] data = new byte[0]; byte[] id = tag.getId(); if (nfcV != null) { try { nfcV.connect(); // Construct the "Read Single Block" command byte[] readCmd = new byte[2 + id.length]; readCmd[0] = 0x20; // Read Single Block command System.arraycopy(id, 0, readCmd, 1, id.length); // Tag ID readCmd[9] = blockNumber; // Block number to read (adjust as needed) // Send the command and receive response data = nfcV.transceive(readCmd); // Close the connection nfcV.close(); } catch (IOException e) { e.printStackTrace(); } }

Make sure to replace blockNumber with the appropriate block address you want to read from the NFCV tag.

Additionally, ensure that your NFC tag is compatible with the NFCV protocol and that the data youre trying to read is stored in the correct memory blocks. You may need to refer to the documentation or specifications of your specific NFC tag to determine the correct commands and memory structure.