Ndef ndef=Ndef.get(tag); NdefFormatable formatable=NdefFormatable.get(tag); formatable.connect(); formatable.format(msg); formatable.close(); ndef.connect(); if (!ndef.isWritable()) { text="Tag is read-only"; else if (ndef.getMaxSize()<size) { text="Message is too big for tag"; ndef.writeNdefMessage(msg); ndef.close();
byte[] SELECT = { (byte) 0x00, // CLA Class (byte) 0xA4, // INS Instruction (byte) 0x04, // P1 Parameter 1 (byte) 0x00, // P2 Parameter 2 (byte) 0x0A, // Length 0x63,0x64,0x63,0x00,0x00,0x00,0x00,0x32,0x32,0x31 // AID }; Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); IsoDep tag = IsoDep.get(tagFromIntent); tag.connect(); byte[] result = tag.transceive(SELECT); if (!(result[0] == (byte) 0x90 && result[1] == (byte) 0x00)) throw new IOException("could not select applet");
NfcA nfcA = NfcA.get(tag); nfcA.connect(); byte[] result1 = nfcA.transceive(new byte[] { (byte)0xA2, /* CMD = WRITE */ (byte)0x02, /* PAGE = 2 */ (byte)0x00, (byte)0x00, (byte)0xFF, (byte)0xFF /* DATA = lock pages 3..15 */ }); byte[] result2 = nfcA.transceive(new byte[] { (byte)0xA2, /* CMD = WRITE */ (byte)0x28, /* PAGE = 40 */ (byte)0x0F, (byte)0x00, (byte)0x00, (byte)0x00 /* DATA = lock pages 16..27 */ });
NdefFormatable formatable = NdefFormatable.get(tag); if (formatable != null) { try { formatable.connect(); try { formatable.format(message); } catch (Exception e) { // let the user know the tag refused to format } } catch (Exception e) { // let the user know the tag refused to connect } finally { formatable.close(); } } else { // let the user know the tag cannot be formatted }
/** * 写数据 * * @param ndefMessage 创建好的NDEF文本数据 * @param tag 标签 * @return */ public static boolean writeTag(NdefMessage ndefMessage, Tag tag) { try { Ndef ndef = Ndef.get(tag); ndef.connect(); ndef.writeNdefMessage(ndefMessage); return true; } catch (Exception e) { } return false; } }
IsoDep iso = IsoDep.get(tag); iso.connect(); iso.setTimeOut(5000); // 5 sec time out iso.transceive(apduCommand); // now send your command
NfcA nfcA = NfcA.get(tag); if (nfcA != null) { try { nfcA.connect(); nfcA.transceive(new byte[] { (byte)0xA2, // WRITE (byte)0x03, // page = 3 (byte)0xE1, (byte)0x10, (byte)0x06, (byte)0x00 // capability container (mapping version 1.0, 48 bytes for data available, read/write allowed) }); nfcA.transceive(new byte[] { (byte)0xA2, // WRITE (byte)0x04, // page = 4 (byte)0x03, (byte)0x00, (byte)0xFE, (byte)0x00 // empty NDEF TLV, Terminator TLV }); } catch (Exception e) { } finally { try { nfcA.close(); } catch (Exception e) { } } }
/** * Tag comm */ private IsoDep mTagCom; @Override public byte[] transceive(final byte[] pCommand) throws CommunicationException { [...] byte[] response = null; [...] // send command to emv card response = mTagCom.transceive(pCommand); [...] return response; }
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(...);
byte[] transceiveProtocol(NfcF nfcF, int systemCode, int requestCode, int timeSlot) { byte d0 = 6; byte d1 = 0; byte d2 = (byte)(systemCode>> 8 & 0xFF); byte d3 = (byte)(systemCode>> 0 & 0xFF); byte d4 = (byte)(requestCode & 0xFF); byte d5 = (byte)(timeSlot & 0xFF); byte[] command = { d0, d1, d2, d3, d4, d5 }; return nfcF.transceive(command); }
Tag tag = intent.getParcelableExtra(NfcAdaptor.EXTRA_TAG); MifareUltralight ul = MifareUltralight.get(tag); if(ul == null) return; // not MIFARE Ultralight byte[] authenticateCommand = { ... }; // data for authentication command byte[] authenticateResponse = ul.transceive(authenticateCommand); // send it ... // etc.
Ndef ndef=Ndef.get(tag); NdefFormatable formatable=NdefFormatable.get(tag); formatable.connect(); formatable.format(msg); formatable.close(); ndef.connect(); if (!ndef.isWritable()) { text=host.getString(R.string.tag_is_read_only); else if (ndef.getMaxSize() < size) { text=host.getString(R.string.message_is_too_big_for_tag); ndef.writeNdefMessage(msg); text=host.getString(R.string.success); ndef.close();
NdefFormatable formatable=NdefFormatable.get(tag); if (formatable != null) { try { formatable.connect(); try { formatable.format(msg); } catch (Exception e) { // let the user know the tag refused to format } } catch (Exception e) { // let the user know the tag refused to connect } finally { formatable.close(); } } else { // let the user know the tag cannot be formatted }
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); NfcA nfcA = NfcA.get(tag); nfcA.connect(); byte[] result = nfcA.transceive(new byte[] { (byte)0x30, /* CMD = READ */ (byte)0x10 /* PAGE = 16 */ });
byte[] rawCmd(NfcF nfcF, byte[] IDm, byte felicaCmd, byte[] payload) throws IOException { final int len = payload != null ? payload.length : 0; final byte[] cmd = new byte[10 + len]; cmd[0] = (byte) (10 + len); cmd[1] = felicaCmd; System.arraycopy(IDm, 0, cmd, 2, IDm.length); if (payload != null) { System.arraycopy(payload, 0, cmd, 10, payload.length); } nfcF.transceive(cmd); }
Ndef ndef = Ndef.get(tag); if (ndef != null) { NdefMessage ndefMesg = ndef.getCachedNdefMessage(); if (ndefMesg != null) { ... } } else { NdefFormatable ndefFormatable = NdefFormatable.get(tag); if (ndefFormatable != null) { // initialize tag with new NDEF message try { ndefFormatable.connect(); ndefFormatable.format(newNdefMessage); } finally { try { ndefFormatable.close(); } catch (Exception e) {} } } }
// test if tag is still connected NfcA nfca = NfcA.get(tags[0]); if (nfca != null) { try { nfca.connect(); byte[] response = nfca.transceive(new byte[] { (byte)0x30, (byte)0x00 }); if ((response != null) && (response.length > 0)) return Boolean.TRUE; } } finally { ndef.close(); } }
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); Ndef ndef = Ndef.get(tag); if (ndef != null) { try { ndef.connect(); ndef.writeNdefMessage(msg); } finally { ndef.close(); } } else { NdefFormatable ndefFormatable = NdefFormatable.get(tag); if (ndefFormatable != null) { try { ndefFormatable.connect(); ndefFormatable.format(message); } finally { ndefFormatable.close(); } } }
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); NdefFormatable ndefFormatable = NdefFormatable.get(tag); if (ndefFormatable != null) { try { ndefFormatable.connect(); ndefFormatable.format(new NdefMessage(NdefRecord.createTextRecord("en", "ABCD"))); } catch (Exception e) { } finally { try { ndefFormatable.close(); } catch (Exception e) { } } }