Java Code Examples for android.nfc.NfcAdapter#FLAG_READER_NO_PLATFORM_SOUNDS

The following examples show how to use android.nfc.NfcAdapter#FLAG_READER_NO_PLATFORM_SOUNDS . 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: 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 2
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);
}