MfClassicNfcTagListener implements NfcTagListener { protected MfClassicNdefOperations createNdefOperations(ApduTag tag, MemoryLayout memoryLayout) { boolean formatted = false; boolean writable = false; MfClassicReaderWriter readerWriter = new AcrMfClassicReaderWriter(tag, memoryLayout); TagInfo tagInfo = null; try { tagInfo = readerWriter.getTagInfo(); if (readerWriter.hasApplicationDirectory()) { ApplicationDirectory applicationDirectory = readerWriter.getApplicationDirectory(); if (applicationDirectory.hasApplication(MfConstants.NDEF_APP_ID)) { formatted = true; Application application = applicationDirectory.openApplication(MfConstants.NDEF_APP_ID); writable = ClassicHandler.isFormattedWritable(application, MfClassicConstants.NDEF_KEY); } else { throw new NfcException("Unknown tag contents"); } } else { if (ClassicHandler.isBlank(readerWriter)) { writable = true; } else throw new NfcException("Unknown tag contents"); } } catch (IOException e) { throw new NfcException(e); } return new MfClassicNdefOperations(readerWriter, tagInfo, formatted, writable); } MfClassicNfcTagListener();  MfClassicNfcTagListener(NdefOperationsListener ndefListener); @Override boolean canHandle(Tag tag); @Override void handleTag(Tag tag);  }
@Test public void testCreateNdefOperations() throws Exception { MemoryMap memoryMap = FileMfClassicReader.loadCardFromFile("mfstd1k_blank.txt"); InMemoryTag tag = new InMemoryTag(memoryMap); MfClassicNfcTagListener nfcTagListener = new MfClassicNfcTagListener(); MfClassicNdefOperations ndefOperations = nfcTagListener.createNdefOperations(tag, MemoryLayout.CLASSIC_1K); assertNotNull(ndefOperations); assertFalse(ndefOperations.isFormatted()); assertTrue(ndefOperations.isWritable()); }