The most important thing is to check if your device supports reading the MIFARE Classic tag:
public static boolean hasMifareClassicSupport() { if (mHasMifareClassicSupport != 0) { return mHasMifareClassicSupport == 1; } // ΠΏΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ Π΅ΡΡΡ Π»ΠΈ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΊΠ° NFC Π½Π° ΡΡΡΡΠΎΠΉΡΡΠ²Π΅ if (NfcAdapter.getDefaultAdapter(mAppContext) == null) { mUseAsEditorOnly = true; mHasMifareClassicSupport = -1; return false; } // Π§ΠΈΠΏΡ Broadcom Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°ΡΡ MIFARE Classic. File device = new File("/dev/bcm2079x-i2c"); if (device.exists()) { mHasMifareClassicSupport = -1; return false; } // Π§ΠΈΠΏΡ NXP ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°ΡΡ MIFARE Classic. device = new File("/dev/pn544"); if (device.exists()) { mHasMifareClassicSupport = 1; return true; } //ΠΏΡΠΎΠ²Π΅ΡΡΠ΅ΠΌ Π½Π°Π»ΠΈΡΠΈΠ΅ Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΡΡ
Π±ΠΈΠ±Π»ΠΈΠΎΡΠ΅ΠΊ Π² ΡΠΈΡΡΠ΅ΠΌΠ΅ File libsFolder = new File("/system/lib"); File[] libs = libsFolder.listFiles(); for (File lib : libs) { if (lib.isFile() && lib.getName().startsWith("libnfc") && lib.getName().contains("brcm") ) { mHasMifareClassicSupport = -1; return false; } } mHasMifareClassicSupport = 1; return true; }
After that you can try to read. First authenticate using authenticateSectorWithKeyA() (if you have the A key, otherwise use authenticateSectorWithKeyB() with the B key). If you get false , the authentication failed (your key was incorrect).
When authentication is successful, you can use readBlock() to read the data (for convenience, you can use sectorToBlock() to convert from a sector index to a block index)
Do not worry about failed authentication: this will not affect the operation of your card.
The read readout using the algorithm described above can be found in the MifareClassicTool application.