0
내 질문에, 안드로이드 NFC API는 이미 "증가"와 "감소"값 블록을 제공하지만, 새로운 MifareClassic 태그가 있다면 내부 값 블록), 어떻게이 새로운 태그에 가치 블록을 구성하기 위해 Android NFC API를 사용할 수 있습니까?안드로이드 NFC API를 통해 MifareClassic에서 값 블록을 구성하는 방법
내 질문에, 안드로이드 NFC API는 이미 "증가"와 "감소"값 블록을 제공하지만, 새로운 MifareClassic 태그가 있다면 내부 값 블록), 어떻게이 새로운 태그에 가치 블록을 구성하기 위해 Android NFC API를 사용할 수 있습니까?안드로이드 NFC API를 통해 MifareClassic에서 값 블록을 구성하는 방법
올바른 형식의 데이터를 태그에 써야합니다. 예를 들어 MIFARE Classic datasheet의 8.6.2 절을 참조하십시오. 블록에 대한 액세스 제어 비트는 키 증분 조작을 할 수 있도록 정확하게 설정되어야한다는
// connect to the tag using a Tag object from an NFC intent
MifareClassic mifare = MifareClassic.get(tag);
mifare.connect();
// need to authenticate first to get access
int sector = blockToSector(blockIndex);
mifare.authenticateSectorWithKeyA(sector, keyA); // you need to know key A
// mifare.authenticateSectorWithKeyB(sector, keyB); // in case you know key B
// construct value block of value zero; "address" byte is set to 0 in this example
byte[] zeroValue = {0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 255, 0, 255 };
mifare.writeBlock(blockIndex, zeroValue);
// increase the value block by some amount
mifare.increment(blockIndex, value);
// result is stored in scratch register inside tag; now write result to block
mifare.transfer(blockIndex);
주의 사항 :
예 안드로이드 코드 블록 blockIndex
가치 블록으로 정수 value
을 저장하도록 당신은 인증하는 데 사용합니다.
대단히 감사합니다! 정말 효과가 있습니다! 죄송합니다. – James
필자는 writeBlock 만 작성하고 쓰기는하지 않습니다 ... 정상입니까? – michele
@michele 수정 됨, 감사합니다. –