第一次后停止 NFC 标签读取
Stop NFC tag reading after the first time
我正在使用 NFC 从使用 jmrtd 库的护照中读取 RFID。问题是我想在成功读取数据后停止接收与 nfc 相关的意图,但目前即使其他一些 activity 在前台,应用程序也会在标签发现时再次重新启动 nfc 读取 activity。
我的代码:
protected void onResume() {
super.onResume();
this.mAdapter.enableForegroundDispatch(this, this.mNfcListener, mIntentFilters, null);
}
//<editor-fold desc="NFC">
public boolean initNFC() {
this.mAdapter = NfcAdapter.getDefaultAdapter(this);
if (this.mAdapter == null) {
return false;
}
Intent i = new Intent(this, getClass());
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
this.mNfcListener = PendingIntent.getActivity(this, 0, i, 0);
IntentFilter tagFilter = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndefFilter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
this.mIntentFilters = new IntentFilter[]{tagFilter, ndefFilter};
return true;
}
protected void onPause() {
mAdapter.disableForegroundDispatch(this);
super.onPause();
}
那是不可能的...
因为您的 activity 具有意向过滤器操作 NDEF_DISCOVERED。
阅读此...
我正在使用 NFC 从使用 jmrtd 库的护照中读取 RFID。问题是我想在成功读取数据后停止接收与 nfc 相关的意图,但目前即使其他一些 activity 在前台,应用程序也会在标签发现时再次重新启动 nfc 读取 activity。
我的代码:
protected void onResume() {
super.onResume();
this.mAdapter.enableForegroundDispatch(this, this.mNfcListener, mIntentFilters, null);
}
//<editor-fold desc="NFC">
public boolean initNFC() {
this.mAdapter = NfcAdapter.getDefaultAdapter(this);
if (this.mAdapter == null) {
return false;
}
Intent i = new Intent(this, getClass());
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
this.mNfcListener = PendingIntent.getActivity(this, 0, i, 0);
IntentFilter tagFilter = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndefFilter = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
this.mIntentFilters = new IntentFilter[]{tagFilter, ndefFilter};
return true;
}
protected void onPause() {
mAdapter.disableForegroundDispatch(this);
super.onPause();
}
那是不可能的... 因为您的 activity 具有意向过滤器操作 NDEF_DISCOVERED。
阅读此...