It is possible to read NFC when app is in background?
Asked Answered
T

1

6

I need to build an application that listens to NFC tags in the background. Is it possible ?. Solution : The application runs a thread which is a socket server with which the web application connects. I need to send read NFC tags to the web application via websocket.

I will be grateful for any suggestions

Thao answered 12/12, 2017 at 23:0 Comment(0)
H
4

Yes, but with limitations. See the docs for more information:

Advanced NFC -> Working with tag technologies and the ACTION_TECH_DISCOVERED intent

https://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html

Essentially, working with tag technologies and the ACTION_TECH_DISCOVERED intent. When a device scans a tag that has NDEF data on it, but could not be mapped to a MIME or URI, the tag dispatch system tries to start an activity with the ACTION_TECH_DISCOVERED intent.

You can then register your app to listen for these intents.

Hickie answered 12/12, 2017 at 23:9 Comment(2)
Does that intent have all the data contained in the nfc?Sheer
@PedroRomanoBarbosa I ended up not going with this solution, but needed it for research. I can see here from the docs onNewIntent gets the tag from the Intent val tagFromIntent: Tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG)... thus I'd be certain that's the whole tag read.Hickie

© 2022 - 2024 — McMap. All rights reserved.