Tabnine Logo
android.nfc.tech
Code IndexAdd Tabnine to your IDE (free)

How to use android.nfc.tech

Best Java code snippets using android.nfc.tech (Showing top 20 results out of 315)

origin: commonsguy/cw-omnibus

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();
origin: stackoverflow.com

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");
origin: stackoverflow.com

 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 */
});
origin: stackoverflow.com

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
 }
origin: RickyYu/Nfc-Android

  /**
   * 写数据
   *
   * @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;
  }
}
origin: stackoverflow.com

 Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
Ndef ndef = Ndef.get(tag);
if (ndef != null) {
 ndef.connect();
 ndef.writeNdefMessage(message);
} else {
 NdefFormatable format = NdefFormatable.get(tag);
 if (format != null) {
  format.connect();
  format.format(message);
 }           
}
origin: stackoverflow.com

IsoDep iso = IsoDep.get(tag);
iso.connect();
iso.setTimeOut(5000); // 5 sec time out
iso.transceive(apduCommand); // now send your command
origin: stackoverflow.com

 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) {
    }
  }
}
origin: stackoverflow.com

/**
  * 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;
 }
origin: stackoverflow.com

 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(...);
origin: stackoverflow.com

 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);
}
origin: stackoverflow.com

 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.
origin: commonsguy/cw-omnibus

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();
origin: stackoverflow.com

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
 }
origin: stackoverflow.com

 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  */
});
origin: stackoverflow.com

 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);
}
origin: stackoverflow.com

 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) {}
    }
  }
}
origin: stackoverflow.com

 // 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();
  }
}
origin: stackoverflow.com

 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();
    }
  }
}
origin: stackoverflow.com

 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) {
    }
  }
}
android.nfc.tech

Most used classes

  • Ndef
  • NdefFormatable
  • IsoDep
  • NfcV
  • MifareUltralight
  • NfcA,
  • NfcB,
  • NfcF,
  • TagTechnology
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now