Java 类android.nfc.NfcAdapter.ReaderCallback 实例源码

项目:nfcspy    文件:NfcManager.java   
@SuppressLint("NewApi")
private void setReaderMode(boolean enable, int delay) {
    if (nfcAdapter == null || !hasHCE())
        return;

    if (!enable) {
        nfcAdapter.disableReaderMode(activity);
        return;
    }

    Bundle opts = new Bundle();
    opts.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000);

    int flags = NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK;
    flags |= NfcAdapter.FLAG_READER_NFC_A;

    // For the 'READ BINARY' problem of Braodcom's NFC stack.
    // Only works on Android 4.4+
    nfcAdapter.enableReaderMode(activity, new ReaderCallback() {

        @Override
        public void onTagDiscovered(Tag tag) {
            Intent i = new Intent().putExtra(EXTRA_TAG, tag);
            tagListener.onNewTagIntent(i);
        }
    }, flags, opts);
}