javaandroidnfciso-15693

Android - Writing to ISO15693 Tags


I'm currently trying to write a couple of bytes to a specific block. My read commands work fine and I am able to read any block of my tag using the code below:

command = new byte[]{
            (byte) 0x02, // Flags
            (byte) 0x23, // Command: Read multiple blocks
            (byte) 0x09, // First block (offset)
            (byte) 0x03  // Number of blocks // MAX READ SIZE: 32 blocks:1F
    };
byte[] data = nfcvTag.transceive(command);

When I try to write with the code below, my app crashes.

Write = new byte[]{
                (byte) 0x02, // Flags
                (byte) 0x21, // Command: Write 1 blocks
                (byte) 0x5A, // First block (offset)
                (byte) 0x41  // Data
        };
    nfcvTag.transceive(Write);

I'm doing this in an AsyncTask and getting the java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() exception.

Any tips? The tag is a STMicroelectronics M24LR04E-R


Solution

  • Figured it out. I was only writing 8 bits of data while the tag has 32 bits per block. Added 3 0x00's and the write was successful.

    Write = new byte[]{
                (byte) 0x02, // Flags
                (byte) 0x21, // Command: Write 1 blocks
                (byte) 0x5A, // First block (offset)
                (byte) 0x41,
                (byte) 0x00,
                (byte) 0x00,
                (byte) 0x00  
        };
    nfcvTag.transceive(Write);