我收到以下代码的“标签丢失”异常。但是,尽管有异常,数据还是写入成功了。为什么抛出异常却写入成功?
nfc.connect();
byte[] arrByt = new byte[7];
arrByt[0] = 0x01; //Command Flag 0x02 works fine
arrByt[1] = 0x21;
arrByt[2] = 0x06;
arrByt[3] = 0x00;
arrByt[4] = 0x00;
arrByt[5] = 0x00;
arrByt[6] = 0x00;
byte[] response = nfc.transceive(arrByt);
我的NFC芯片
Type V (ISO/IEC 15693 / Vicinity), Tag Type SL2 ICS2001 (ICODE SLI), Manufacturer NXP Semiconductors (Germany)
here talked over 但是没有结果:(
最佳答案
当 NfcV 标签返回非成功代码时,android 的 NFC 堆栈假定它是一个异常并抛出“标签丢失”。
为避免此异常,您可以使用命令 0x02 并且正确的字节数组变为:
arrByte = {0x02, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00};其中 0x02 是标志命令,0x21 是写单 block 命令,0x06 是 block 号,剩余的是 4 个字节的数据。希望这会有所帮助。
关于android - 为什么 NFC 标签数据写入成功?标签丢失异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12780813/