Skip to content

Reading NTAG213/MifareClassic #13

@mbigant

Description

@mbigant

Hi,
I'm trying to read NTAG213 and MifareClassic card but issuing an java.lang.NullPointerException in AndroidNfcReaderAdapter.kt:94.
After some researches I found that tagTechnology is null and I notice that it is not set (like currentCardProtocol also) in every case in the onTagDiscovered method.

override fun onTagDiscovered(tag: Tag) {
    logger.info("{}: card discovered: {}", name, tag)
    isCardChannelOpen = false
    try {
      for (technology in tag.techList) when (technology) {
        IsoDep::class.qualifiedName -> {
          currentCardProtocol = IsoDep::class.qualifiedName!!
          tagTechnology = IsoDep.get(tag)
        }
        MifareUltralight::class.qualifiedName -> {
          currentCardProtocol = MifareUltralight::class.qualifiedName!!
          tagTechnology = MifareUltralight.get(tag)
        }
        NfcA::class.qualifiedName -> {
          val tagA = NfcA.get(tag)
          uid = tagA.tag.id
          powerOnData =
              JSONObject()
                  .put("type", "A")
                  .put("uid", HexUtil.toHex(uid))
                  .put("atqa", HexUtil.toHex(tagA.atqa))
                  .put("sak", HexUtil.toHex(tagA.sak))
                  .toString()
        }
        NfcB::class.qualifiedName -> {
          val tagB = NfcB.get(tag)
          uid = tagB.tag.id
          powerOnData =
              JSONObject()
                  .put("type", "B")
                  .put("uid", HexUtil.toHex(uid))
                  .put("applicationData", HexUtil.toHex(tagB.applicationData))
                  .put("protocolInfo", HexUtil.toHex(tagB.protocolInfo))
                  .toString()
        }
        else -> logger.warn("{}: unreachable code", name)
      }
      cardInsertionWaiterAsynchronousApi.onCardInserted()
    } catch (_: NoSuchElementException) {
      tagTechnology = null
      logger.warn("{}: unsupported card technology", name)
    }
  }

When matching NfcA or NfcB which is my case there is no tagTechnology affectation. Is there any reason ?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions