我有一个应用程序,必须能够连续读取主屏幕上的NFC标签。有时候,即使我在内置读取器上多次触摸卡,从2-3厘米的距离也可以很好地读取,有时5-10秒钟没有任何反应。
我认为NFC读取器可能会在一段时间后进入睡眠模式,或者我不知道是什么原因造成的。
有什么方法可以确保连续读取(至少在插入设备时?)>
在onCreate()
中:
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, (new Intent(this, this.getClass())).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
在
onResume()
中:
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if ( nfcAdapter != null ) {
if ( !nfcAdapter.isEnabled() ) {
this.showNFCSettings();
}
nfcAdapter.enableForegroundDispatch(this, this.pendingIntent, null, null);
}
我有一个应用程序,必须能够连续读取主屏幕上的NFC标签。有时从2-3厘米的距离可以很好地读取,有时5-10秒钟没有任何反应,即使我...
如果找到了标签,并且您在1分钟内不使用它进行读写,则nfc将自动关闭,您应该关闭/打开nfc或关闭屏幕/打开。如果您继续发送和标记命令并继续接收某些内容,该界面将保持打开状态。