As I know when an Android phone gets an NFC tag touched, it will send an event (NDEF_DISCOVERED intent), but Android doesn't seem to care whether this tag is staying in place. My solution is to lock the screen and then unlock it. If the tag is still there, I can read it again. This is obviously a silly way. Is there any smarter way to do it?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
As part of the NFC intent received by your activity, you will also receive a tag-handle (
Tag
object) in an intent extra:Depending on the type of tag, you can then get an instance of the specific tag technology. For instance, if it's an NDEF tag, you can get:
Then you can connect to the tag using the connect() method:
After that you can check if the tag is still "connected" to the device by periodically trying to read from the tag:
Note that this will only work if your activity is in the foreground all the time and the screen remains on.
There is a function that checks to see if the card is still connected called
isConnected()
. Can be used like this: