Skip to content

Instantly share code, notes, and snippets.

@salmangadit
Created June 25, 2013 04:20
Show Gist options
  • Save salmangadit/5855914 to your computer and use it in GitHub Desktop.
Save salmangadit/5855914 to your computer and use it in GitHub Desktop.
Android intent for Mifare Classic 1K
try {
// 5.1) Connect to card
mfc.connect();
boolean auth = false;
String cardData = null;
// 5.2) and get the number of sectors this card has..and loop
// thru these sectors
int secCount = mfc.getSectorCount();
int bCount = 0;
int bIndex = 0;
for (int j = 0; j < secCount; j++) {
// 6.1) authenticate the sector
auth = mfc.authenticateSectorWithKeyA(0, MifareClassic.KEY_DEFAULT);
if (auth) {
// 6.2) In each sector - get the block count
bCount = mfc.getBlockCountInSector(0);
bIndex = 0;
for (int i = 0; i < bCount; i++) {
bIndex = mfc.sectorToBlock(0);
// 6.3) Read the block
data = mfc.readBlock(bIndex);
// 7) Convert the data into a string from Hex format.
Log.v(TAG, getHexString(data, data.length));
bIndex++;
uid = getHexString(data, data.length);
}
//invokeRestAPI();
} else { // Authentication failed - Handle it
}
}
} catch (IOException e) {
Log.v(TAG, e.getMessage() == null ? e.getMessage(): "Cannot detect error");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment