Code example for MifareClassic

Methods: close, connect, getBlockCount, getBlockCountInSector, getSectorCount, readBlock, sectorToBlock

6
        }); 
    } 
     
    void connectMifare(MifareClassic mifare) {
	    		try { 
	    			mifare.connect();
	    			int blockCount = mifare.getBlockCount();
	    			int blockCountForSector = mifare.getBlockCountInSector(0);
	    			int sectorCount = mifare.getSectorCount();
	    			Log.i(TAG, "block count: " + blockCount);
	    			Log.i(TAG, "sector count: " + sectorCount);
	    			Log.i(TAG, "block for sector count: " + blockCountForSector);
	    			Log.i(TAG, "first block of sector0: " + mifare.sectorToBlock(0));
	    			 
	    			byte []blockData = mifare.readBlock(0);
	    			Log.i(TAG, "data for block: " + blockData);
	    			 
	    			 
	    		} catch (IOException e) {
	    			Log.e(TAG, "caught IO exception while connection to mifare", e);
	    		} finally { 
	    			try { 
	    				mifare.close();
	    			} catch(IOException e) {
	    				Log.e(TAG, "IOException while closing mifare", e);
	    			} 
	    		} 
	    		Log.i(TAG, "done reading mifare");