Java Code Examples for android.nfc.NfcAdapter#ReaderCallback

The following examples show how to use android.nfc.NfcAdapter#ReaderCallback . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TagDispatcher.java    From GreenBits with GNU General Public License v3.0 10 votes vote down vote up
private void enableReaderMode(NfcAdapter adapter) {
      Bundle options = new Bundle();
      /* This is a work around for some Broadcom chipsets that does
       * the presence check by sending commands that interrupt the
       * processing of the ongoing command.
       */
      //options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000);
options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 30000);
      NfcAdapter.ReaderCallback callback = new NfcAdapter.ReaderCallback() {
              public void onTagDiscovered(Tag tag) {
                  listener.tagDiscovered(tag);
              }
          };
      adapter.enableReaderMode(activity,
                               callback,
                               NfcAdapter.FLAG_READER_NFC_A |
                               NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK |
                               NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS,
                               options);
  }
 
Example 2
Source File: NfcReaderDispatcher.java    From yubikit-android with Apache License 2.0 6 votes vote down vote up
/**
 * Start intercepting nfc events
 * @param activity activity that is going to receive nfc events
 * Note: invoke that while activity is in foreground
 */
private void enableReaderMode(Activity activity, final NfcConfiguration nfcConfiguration) {
    NfcAdapter.ReaderCallback callback = new NfcAdapter.ReaderCallback() {
        public void onTagDiscovered(Tag tag) {
            handler.onTag(tag);
        }
    };
    Bundle options = new Bundle();
    options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 50);
    int READER_FLAGS = NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NFC_B;
    if (nfcConfiguration.isDisableNfcDiscoverySound()) {
        READER_FLAGS |= NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS;
    }

    if (nfcConfiguration.isSkipNdefCheck()) {
        READER_FLAGS |= NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK;
    }
    adapter.enableReaderMode(activity, callback, READER_FLAGS, options);
}
 
Example 3
Source File: TagDispatcher.java    From nordpol with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
private void enableReaderMode(NfcAdapter adapter) {
    Bundle options = new Bundle();
    if(broadcomWorkaround) {
        /* This is a work around for some Broadcom chipsets that does
         * the presence check by sending commands that interrupt the
         * processing of the ongoing command.
         */
        options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, DELAY_PRESENCE);
    }
    NfcAdapter.ReaderCallback callback = new NfcAdapter.ReaderCallback() {
            public void onTagDiscovered(Tag tag) {
                dispatchTag(tag);
            }
        };
    int flags = NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_NFC_B;
    if(disableSounds) {
        flags = flags | NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS;
    }
    if(disableNdefCheck) {
        flags = flags | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK;
    }
    adapter.enableReaderMode(activity, callback, flags, options);
}
 
Example 4
Source File: TagDispatcher.java    From WalletCordova with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void enableReaderMode(NfcAdapter adapter) {
      Bundle options = new Bundle();
      /* This is a work around for some Broadcom chipsets that does
       * the presence check by sending commands that interrupt the
       * processing of the ongoing command.
       */
      //options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000);
options.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 30000);
      NfcAdapter.ReaderCallback callback = new NfcAdapter.ReaderCallback() {
              public void onTagDiscovered(Tag tag) {
                  listener.tagDiscovered(tag);
              }
          };
      adapter.enableReaderMode(activity,
                               callback,
                               NfcAdapter.FLAG_READER_NFC_A |
                               NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK |
                               NfcAdapter.FLAG_READER_NO_PLATFORM_SOUNDS,
                               options);
  }
 
Example 5
Source File: NfcManager.java    From smartcard-reader with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public NfcManager(Activity activity, NfcAdapter.ReaderCallback readerCallback) {
    mActivity = activity;
    mReaderCallback = readerCallback;
    mNfcAdapter = NfcAdapter.getDefaultAdapter(activity);
}