Package org.nfctools.ndef

Examples of org.nfctools.ndef.NdefException


  @Override
  public List<Record> readNdefMessage(MfCard card) throws IOException {

    if (!MadUtils.hasApplicationDirectory(card, readerWriter))
      throw new NdefException("unknown service type");

    ApplicationDirectory applicationDirectory = MadUtils.getApplicationDirectory(card, readerWriter);

    if (applicationDirectory.hasApplication(MfNdefConstants.NDEF_APP_ID)) {

      Application application = applicationDirectory.openApplication(MfNdefConstants.NDEF_APP_ID);

      byte[] tlvWrappedNdefMessage = application.read(new KeyValue(Key.A, MfConstants.NDEF_KEY));

      if (log.isDebugEnabled())
        log.debug(NfcUtils.convertBinToASCII(tlvWrappedNdefMessage));

      TypeLengthValueReader lengthValueReader = new TypeLengthValueReader(new ByteArrayInputStream(
          tlvWrappedNdefMessage));

      List<Record> records = new ArrayList<Record>();

      while (lengthValueReader.hasNext()) {
        Tlv tlv = lengthValueReader.next();
        if (tlv instanceof NdefMessageTlv) {
          NdefMessage ndefMessage = ndefMessageDecoder.decode(((NdefMessageTlv)tlv).getNdefMessage());
          for (Record record : ndefMessageDecoder.decodeToRecords(ndefMessage)) {
            records.add(record);
          }
        }
      }
      return records;
    }
    else {
      throw new NdefException("unknown service type");
    }
  }
View Full Code Here

TOP

Related Classes of org.nfctools.ndef.NdefException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.