int ttype = mif.getType(); Log.d(TAG, "MifareClassic tag type: " + ttype); int tsize = mif.getSize(); Log.d(TAG, "tag size: " + tsize); int s_len = mif.getSectorCount(); Log.d(TAG, "tag sector count: " + s_len); int b_len = mif.getBlockCount(); Log.d(TAG, "tag block count: " + b_len); try { mif.connect(); if (mif.isConnected()){ if (mif.authenticateSectorWithKeyA(i, MifareClassic.KEY_MIFARE_APPLICATION_DIRECTORY)) { isAuthenticated = true; } else if (mif.authenticateSectorWithKeyA(i, MifareClassic.KEY_DEFAULT)) { isAuthenticated = true; } else if (mif.authenticateSectorWithKeyA(i,MifareClassic.KEY_NFC_FORUM)) { isAuthenticated = true; } else { int block_index = mif.sectorToBlock(i); byte[] block = mif.readBlock(block_index); String s_block = NfcUtils.ByteArrayToHexString(block); Log.d(TAG, s_block);
Tag tag = getIntent().getParcelableExtra(NfcAdapter.EXTRA_TAG); MifareClassic mifareClassicTag = MifareClassic .get(tag); mifareClassicTag.connect(); // The transceive command sends command directly to the tag. Internally it wraps the given command in a direct transmit command and sends it to the NFC chip which forwards it to the tag mifareClassicTag.transceive(...);
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); MifareClassic clas = MifareClassic.get(tagFromIntent); try { clas.connect(); if (!DefaultAuthenticate(clas)) throw new Exception("Unable to authenticate using default key"); String myData = new String(clas.readBlock(clas .sectorToBlock(MY_DATA_SECTOR)), "US-ASCII"); clas.close(); } catch (Exception ex) { ShowMessage(ex.getMessage()); }
private void WriteCard(Intent intent) { String action = intent.getAction(); if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) { Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); MifareClassic mfc = MifareClassic.get(tagFromIntent); try { mfc.connect(); boolean authA = mfc.authenticateSectorWithKeyA(1, MifareClassic.KEY_DEFAULT); Log.d("MainActivity.WriteCard()", String.valueOf(authA) + " "); mfc.writeBlock(mfc.sectorToBlock(1), new byte[] { 'A', 'l','v', 'a', 'r', 'e', 'z', ' ', ' ', ' ', ' ', ' ', ' ',' ', ' ', ' ' }); mfc.close(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } return; }
android.nfc.tech.MifareClassic mifareClassic = MifareClassic.get(tag); if(mifareClassic == null) { throw new IllegalArgumentException("No MifareClassic");
tagTech = IsoDep.get(tag); } else if (tech.equals(android.nfc.tech.MifareClassic.class.getName())) { tagTech = MifareClassic.get(tag);
android.nfc.tech.MifareClassic mifareClassic = MifareClassic.get(tag);