简体   繁体   English

mifare classic 1k-Android-读取失败

[英]mifare classic 1k - Android - Tranceive failed on reading block

I am trying to read blocks with mifare classic card 1k and android nfc (on galaxy nexus). 我正在尝试使用mifare经典卡1k和android nfc(在银河系上)读取块。

private final int mMaxSize = 64;

mClassic.connect();

boolean success = mClassic.authenticateSectorWithKeyA(1, MifareClassic.KEY_DEFAULT );
final ByteArrayBuffer b = new ByteArrayBuffer(mMaxSize);

if (success)
{   
    b.append(mClassic.readBlock(0), 0, 16);
    b.append(mClassic.readBlock(1), 0, 16);
    b.append(mClassic.readBlock(2), 0, 16);
    b.append(mClassic.readBlock(3), 0, 16);
}

If I want to read sector 0, that's all ok. 如果我想读取扇区0,那没关系。 But if I want to read a different sector (for example sector 1), success has true value, but when the app go to readBlock() , an IOException is triggered and I have returned tranceiver failed. 但是,如果我想读取其他扇区(例如扇区1),则成功具有真正的价值,但是当应用程序进入readBlock() ,将触发IOException ,并且我返回的收发器失败。

What I am doing wrong? 我做错了什么?

In your code example you're authenticating for sector 1 but then try to read blocks from sector 0 . 在您的代码示例中,您正在对扇区1进行身份验证,然后尝试从扇区0中读取块。 Remember sector and block numbers are zero-based. 请记住,扇区号和块号是从零开始的。 You may also be interested in blockToSector(int block) . 您可能也对blockToSector(int block)感兴趣。

you should 你应该

b.append(mClassic.readBlock(4), 0, 16);
b.append(mClassic.readBlock(5), 0, 16);
b.append(mClassic.readBlock(6), 0, 16);
b.append(mClassic.readBlock(7), 0, 16);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM