Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
How to detect NFC tag removal event?

I develop an Android app to read/write on contactless smart cards through NFC. I need to detect when the card is pulled out of range. I tried to use

 NFCAdapter.OnTagRemovedListener{
        card_connected2.visibility =  View.VISIBLE
        card_connectedgreen.visibility =  View.GONE
        Toast.makeText(this@InquiryActivity, "card is disconnected", Toast.LENGTH_LONG).show()
}

but this seems wrong and does not work. I also read about NfcAdapter.ignore(), but I can't find any example about how to use it. How can I get the above callback to work?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The OnTagRemovedListener interface is used to specify the callback for the NfcAdapter.ignore() method. Consequently, you need to call ignore() with the desired callback. E.g., if you want to execute the code above, with a debounce timeout of 1000 ms, you could use something like this:

// nfcAdapter: your instance of the NfcAdapter
// tag: the tag handle that you obtained from the NFC intent or the onTagDetected() callback

nfcAdapter.ignore(tag, 1000, NfcAdapter.OnTagRemovedListener {
        card_connected2.visibility =  View.VISIBLE
        card_connectedgreen.visibility =  View.GONE
        Toast.makeText(this@InquiryActivity, "card is disconnected", Toast.LENGTH_LONG).show()
}, Handler(Looper.getMainLooper()))

Note that nfcAdapter and tag need to be defined accordingly. The callback function will be invoked on the main (UI) thread.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda