Android 检测到Nfc标记/侦听器丢失
我一直在为NFC MifareClassic卡工作。我已经在卡片上读写了数据。 当检测到标记时,我想向用户显示一个通知Android 检测到Nfc标记/侦听器丢失,android,nfc,Android,Nfc,我一直在为NFC MifareClassic卡工作。我已经在卡片上读写了数据。 当检测到标记时,我想向用户显示一个通知 @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); // 1) Parse the intent and get the action that triggered this intent String action = int
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// 1) Parse the intent and get the action that triggered this intent
String action = intent.getAction();
if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
// 3) Get an instance of the TAG from the NfcAdapter
Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
AppController.getInstance().setTag(tagFromIntent);
}
}
但当标签被移开时,这就是我需要的。我想向用户显示标签不再可用。有监听器吗?当标签不再可用时,无法检测到,因为标签不通过靠近标签读取器的方式工作,而是在通过读取器时读取标签 当然,当标签在一段时间内超出范围时,您可以实现自己的检测。如果超出范围,您可以使用委托触发您自己的事件
具有此
忽略方法。它是在API 24中添加的。我还没有测试它,但它似乎提供了你需要的。它允许您为具体的标记设置OnTagRemovedListener
有一个名为isConnected()。可以这样使用:
try {
ndef.connect();
while(ndef.isConnected()){
//Your code here
}
} catch (IOException e) {
//Error
}
可能重复指定的,是否可以通过轮询进行。然而,据我所知,没有基于事件的方法。