Best code examples for Android MifareClassic class (android.nfc.tech.MifareClassic)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android MifareClassic class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android MifareClassic examples from Open Source projects
This code example shows how to use the following methods: close, connect, getBlockCount, getBlockCountInSector, getSectorCount
        }); 
    } 
     
    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);

8
CodeRank
This code example shows how to use the following methods: authenticateSectorWithKeyA, authenticateSectorWithKeyB, getBlockCountInSector, getSectorCount, sectorToBlock
     * </ul> 
     * @see #authenticate(int, byte[], boolean) 
     */ 
    public int writeBlock(int sectorIndex, int blockIndex, byte[] data,
            byte[] key, boolean useAsKeyB) {
        if (mMFC.getSectorCount()-1 < sectorIndex) {
            return 1; 
        } 
        if (mMFC.getBlockCountInSector(sectorIndex)-1 < blockIndex) {
            return 2; 
        } 
        if (data.length != 16) {
            return 3; 
        } 
        if (!authenticate(sectorIndex, key, useAsKeyB)) {
            return 4; 
        } 
        // Write block. 
        int block = mMFC.sectorToBlock(sectorIndex) + blockIndex;
        try { 

6
CodeRank
This code example shows how to use the following methods: authenticateSectorWithKeyA, close, connect, readBlock, writeBlock
    	byte[] balance_bytes = new byte[2];
    	int balance = 0;
//    	byte[] myKeyA = {(byte)0x59, (byte)0xBB, (byte)0xB4, (byte)0xD7, (byte)0xC1, (byte)0x9F};				 
//    	byte[] myKeyB = {(byte)0x8F, (byte)0x69, (byte)0xF5, (byte)0x45, (byte)0xF9, (byte)0x79}; 
    	byte[] myKeyA = mainActivity.mSectors.get(4).getKeyA();
    	mfc.connect();
    	if (mfc.authenticateSectorWithKeyA(4, myKeyA)) {
    		data = mfc.readBlock(0 + 4 * 4);
			System.arraycopy(data, 0, balance_bytes, 0, 2);
			balance = (balance_bytes[1] & 0x0FF) * 256 + (balance_bytes[0]  & 0x0FF);
			publishProgress("First 16 bytes on section 4:"); 
			publishProgress(formatHex(data));
			publishProgress(String.format("Original balance %.2f", balance / 100.00));
    	} 
    	if (mfc.authenticateSectorWithKeyA(4, myKeyA)) {
    		balance += this.offset * 100;
    		publishProgress(String.format("Proposed balance %.2f", balance / 100.00));
    		if (balance > 0 && balance < 100000) {
        		balance_bytes[1] = (byte)((balance / 256) & 0x0FF);
        		balance_bytes[0] = (byte)((balance % 256) & 0x0FF);

6
CodeRank
This code example shows how to use the following methods: authenticateSectorWithKeyA, authenticateSectorWithKeyB, getBlockCountInSector, getSectorCount, sectorToBlock
     * </ul> 
     * @see #authenticate(int, byte[], boolean) 
     */ 
    public int writeBlock(int sectorIndex, int blockIndex, byte[] data,
            byte[] key, boolean useAsKeyB) {
        if (mMFC.getSectorCount()-1 < sectorIndex) {
            return 1; 
        } 
        if (mMFC.getBlockCountInSector(sectorIndex)-1 < blockIndex) {
            return 2; 
        } 
        if (data.length != 16) {
            return 3; 
        } 
        if (!authenticate(sectorIndex, key, useAsKeyB)) {
            return 4; 
        } 
        // Write block. 
        int block = mMFC.sectorToBlock(sectorIndex) + blockIndex;
        try { 

5
CodeRank
This code example shows how to use the following methods: authenticateSectorWithKeyA, authenticateSectorWithKeyB, getBlockCountInSector, getSectorCount, sectorToBlock
     * </ul> 
     * @see #authenticate(int, byte[], boolean) 
     */ 
    public int writeBlock(int sectorIndex, int blockIndex, byte[] data,
            byte[] key, boolean useAsKeyB) {
        if (mMFC.getSectorCount()-1 < sectorIndex) {
            return 1; 
        } 
        if (mMFC.getBlockCountInSector(sectorIndex)-1 < blockIndex) {
            return 2; 
        } 
        if (data.length != 16) {
            return 3; 
        } 
        if (!authenticate(sectorIndex, key, useAsKeyB)) {
            return 4; 
        } 
        // Write block. 
        int block = mMFC.sectorToBlock(sectorIndex) + blockIndex;
        try { 

5
CodeRank
Related Android MifareClassic Questions & Answers:
See Code Examples for Android MifareClassic Methods: