【发布时间】:2017-02-01 08:39:14
【问题描述】:
我正在使用 NFC 使用 jmrtd 库从护照中读取 RFID。问题是我想在成功读取数据后停止接收与 nfc 相关的意图,但目前即使其他一些活动处于前台,应用程序也会在标签发现时再次启动 nfc 读取活动。
我的代码:
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();
}
【问题讨论】: