private byte[] readMifareUltralight(MifareUltralight tag) throws IOException { byte[] payload = new byte[MIFARE_ULTRALIGHT_SIZE_LIMIT]; try { tag.connect(); for (int i = 4; i < 16; i++) { System.arraycopy( tag.readPages(i), 0, payload, (i - 4) * 4, 4 ); } } finally { tag.close(); } return payload; }
private byte[] readTag(Tag tag) throws IOException, FormatException, ReadingTagException { List<String> tech = Arrays.asList(tag.getTechList()); if (tech.contains(Ndef.class.getName())) { Log.v(TAG, "Read formatted tag."); return readNdeftag(Ndef.get(tag)); } else if (tech.contains(MifareUltralight.class.getName())) { Log.v(TAG, "Read Mifare ultralight tag."); return readMifareUltralight(MifareUltralight.get(tag)); } Toast.makeText(this, "No supported tag found.", Toast.LENGTH_SHORT).show(); Log.e(TAG, "No supported tag found: " + tech); throw new ReadingTagException("No supported tag found."); }
private void clearTag(MifareUltralight tag) { byte[] payload = new byte[MIFARE_ULTRALIGHT_SIZE_LIMIT]; Arrays.fill(payload, (byte) 0); write(tag, payload); }