2
我正在开发需要读取NFC卡(卡技术是NFC-F)的Android应用程序。在那里,我总是得到以下异常:TagLostException当在Android上读取NFC-F卡时
android.nfc.TagLostException:标记丢失。
这里是我的代码:
private void handleIntent(Intent intent) {
String action = intent.getAction();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
} else if (NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
} else if(NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)) {
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
if (tag != null) {
NfcF nfcf = NfcF.get(tag);
try {
nfcf.connect();
byte[] AUTO_POLLING_START = {(byte) 0xE0, 0x00, 0x00, 0x40, 0x01};
byte[] response = nfcf.transceive(AUTO_POLLING_START);
nfcf.close();
} catch (Exception e) {
e.printStackTrace();
mTextView.setText(e.toString());
}
}
}
}
谁能帮助我对这个问题?
改进的格式 –