【问题标题】:Stop NFC tag reading after the first time第一次后停止 NFC 标签读取
【发布时间】: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();
    }

【问题讨论】:

    标签: android nfc


    【解决方案1】:

    这是不可能的... 因为您的活动具有意图过滤器操作 NDEF_DISCOVERED。

    读这个... How to detect NFC tag was removed

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-15
      • 2019-04-19
      • 2015-01-06
      相关资源
      最近更新 更多