简体   繁体   English

从javax.smartcardio读取事件以检测NFC标签的存在

[英]Reading events from javax.smartcardio to detect presence of NFC tag

I am building a web application to read NFC tags using an ACS ACR1222L NFC reader. 我正在构建一个Web应用程序,以使用ACS ACR1222L NFC阅读器读取NFC标签。 The application needs to respond by reading the NFC tag serial number whenever a tag is brought close to the reader. 每当标签靠近阅读器时,应用程序都需要通过读取NFC标签序列号来做出响应。

I have read about the ascscm.jar for Android which has an onStateChangeListener. 我已经阅读了有关具有onStateChangeListener的Android的ascscm.jar的信息。 Using this the Android UsbManager detects the change in state from CARD_PRESENT to CARD_ABSENT and vice versa. Android UsbManager使用此工具检测状态从CARD_PRESENT更改为CARD_ABSENT的情况,反之亦然。 However, I wasn't able to find a parallel to this in javax.smartcardio. 但是,我在javax.smartcardio中找不到与此类似的东西。 Right now I am using a while(true) loop in my thread to continuously poll for checking if a card is present. 现在,我在线程中使用while(true)循环不断轮询以检查是否有卡。 I want to change this to an event driven approach using an eventListener so that my code reacts only when a CARD_PRESENT state is achieved and does not need to poll continuously. 我想使用eventListener将其更改为事件驱动的方法,以便我的代码仅在达到CARD_PRESENT状态时才做出反应,而无需连续轮询。

You are probably looking for something like waitForCardPresent(long timeout) . 您可能正在寻找诸如waitForCardPresent(long timeout)类的东西。 You may still need a loop, but the thread will not be polling all the time (well, depending of the implementation of course, but it certainly is not supposed to poll). 您可能仍然需要一个循环,但是线程不会一直轮询(当然,这取决于实现方式,但是当然不应该轮询)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM