我想存儲一個整數值並用API函數遞增或遞減它。android nfc - mifare classic 1k增量操作失敗失敗
我已經readed與實用的卡,這是塊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();
我在this.mClassic.increment(firstBlock, 1);
我不明白我在做什麼錯返回tranceive failed
...誰可以幫我? 非常感謝。
你能清理一下你的代碼並告訴我們你想要做什麼嗎? – ThomasRS 2013-05-10 11:35:48
我想存儲一個整數值並用API函數遞增或遞減它。 – michele 2013-05-10 13:21:29