我想存储一个整数值并使用 API 函数递增或递减它。
我已经用实用程序读取了卡片,这是第 5 块的内容:
似乎没有任何值块。
这是我的代码:
int sector = 5;
this.mClassic.connect();
boolean success = this.mClassic.authenticateSectorWithKeyA(sector, MifareClassic.KEY_DEFAULT );
if(success){
int firstBlock = mClassic.sectorToBlock(sector);
Log.i("MIFARE CLASSIC", "first block of the given sector:" + firstBlock);
//set the value = 0
byte[] zeroValue = {0, 0, 0, 0, 0,0,0,0,0,0,0,0,0,0,0,0,};
//save this value
mClassic.writeBlock(firstBlock, zeroValue);
//increment the value and store it
this.mClassic.increment(firstBlock, 1);
this.mClassic.transfer(firstBlock);
// read the incremented value by converting it in integer from bytearray
b = readSector(firstBlock);
data = b.toByteArray();
value = 0;
for (int i = 0; i < data.length; i++)
{
value = (value << 8) + (data[i] & 0xff);
}
Log.i("MIFARE CLASSIC", "After increment " + value);
}
mClassic.close();
我回来tranceive failed
了, this.mClassic.increment(firstBlock, 1);
我不明白我做错了什么......谁能帮助我?非常感谢。