Search in sources :

Example 1 with ReaderCallback

use of android.nfc.NfcAdapter.ReaderCallback in project nfcspy by sinpolib.

the class NfcManager method setReaderMode.

@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);
}
Also used : ReaderCallback(android.nfc.NfcAdapter.ReaderCallback) Bundle(android.os.Bundle) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Tag(android.nfc.Tag) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 ReaderCallback (android.nfc.NfcAdapter.ReaderCallback)1 Tag (android.nfc.Tag)1 Bundle (android.os.Bundle)1