Android MifareClassic - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android MifareClassic class.

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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: getBlockCountInSector
     * Return the block count in a specific sector. 
     * @param sectorIndex Index of a sector. 
     * @return Block count in given sector. 
     */ 
    public int getBlockCountInSector(int sectorIndex) {
        return mMFC.getBlockCountInSector(sectorIndex);
    } 
 
    /** 
     * Check if the reader is connected to the tag. 
     * @return True if the reader is connected. False otherwise. 
     */ 
    public boolean isConnected() { 
        return mMFC.isConnected();
    } 
 
    /** 
     * Connect the reader to the tag. 
     */ 
    public void connect() { 
Full Snippet Info
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: authenticateSectorWithKeyA, authenticateSectorWithKeyB, getBlockCountInSector, getSectorCount, sectorToBlock
	 *         <li>-1 - Error while writing to tag.</li> 
	 *         </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
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: connect, getSectorCount
	public static final int TYPE_MANUFACTURER = 3;
 
	public Mifare(MifareClassic m) throws IOException {
		mf = m;
 
		mf.connect();
 
		keysA = new byte[mf.getSectorCount()][6];
		keysB = new byte[mf.getSectorCount()][6];
	} 
 
	public ArrayList<String[]> testDefaultKeys() {
		ArrayList<String[]> mItems = new ArrayList<String[]>();
 
		try { 
			// Check default key 
			boolean auth;
 
			for (int s = 0; s < mf.getSectorCount(); s++) {
				// Clave A 
Full Snippet Info
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods: blockToSector, isConnected
	 * @return int lastSectorIndex 
	 * @throws FsgException 
	 */ 
	public int getLastSector(MifareClassic tag) throws FsgException{
		int lastSectorIndex = 1;
		if (tag.isConnected()){
			lastSectorIndex = tag.blockToSector(getEmptyBlock(tag));
		} else { 
			System.out.println("Tag disconnected!");
		} 
		return lastSectorIndex;
	} 
	 
	public void cleanTag(Intent intent) throws FsgException{
		//System.out.println("Cleaning Tag..."); 
		byte[] rights = new byte[4];
		rights[0] = setBit(rights[0], 0);
		rights[0] = setBit(rights[0], 1);
		rights[0] = setBit(rights[0], 2);
		rights[0] = setBit(rights[0], 3);
Full Snippet Info
3
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android MifareClassic Questions & Answers:

See Code Examples for Android MifareClassic Methods: