Java Code Examples for android.nfc.NfcAdapter#enableReaderMode()
The following examples show how to use
android.nfc.NfcAdapter#enableReaderMode() .
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 |
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: MainActivity.java From LecteurOPUS with GNU General Public License v3.0 | 6 votes |
private void enableReaderMode() { Log.i(TAG, "Enabling reader mode"); Activity activity = this; NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity); if (!nfc.isEnabled()) { AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create(); alertDialog.setTitle(getString(R.string.disable_title)); alertDialog.setMessage(getString(R.string.nfc_disable)); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); } }); alertDialog.show(); } else if (nfc != null) { nfc.enableReaderMode(activity, mCardReader, FLAG_MIFARE | FLAG_OPUS, null); } }
Example 3
Source File: NfcDeviceFragment.java From ESeal with Apache License 2.0 | 6 votes |
private void enableNfcReaderMode() { NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity()); if (nfcAdapter != null) { if (nfcAdapter.isEnabled()) { nfcAdapter.enableReaderMode(getActivity(), mNfcUtility, NfcUtility.NFC_TAG_FLAGS, null); showSnackbar(getString(R.string.text_hint_close_to_nfc_tag)); } else { Snackbar snackbar = Snackbar.make(foldingCellLock, getString(R.string.error_nfc_not_open), Snackbar.LENGTH_SHORT) .setAction(getString(R.string.text_hint_open_nfc), new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS); startActivity(intent); } }); ((TextView) (snackbar.getView().findViewById(R.id.snackbar_text))).setTextColor(ContextCompat.getColor(getContext(), R.color.blue_grey_100)); snackbar.show(); } } }
Example 4
Source File: DeviceOperationActivity.java From ESeal with Apache License 2.0 | 6 votes |
private void enableNfcReaderMode() { NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter != null) { if (nfcAdapter.isEnabled()) { nfcAdapter.enableReaderMode(this, mNfcUtility, NfcUtility.NFC_TAG_FLAGS, null); showSnackbar(getString(R.string.text_hint_close_to_nfc_tag)); } else { Snackbar snackbar = Snackbar.make(cardSetting, getString(R.string.error_nfc_not_open), Snackbar.LENGTH_SHORT) .setAction(getString(R.string.text_hint_open_nfc), new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS); startActivity(intent); } }); ((TextView) (snackbar.getView().findViewById(R.id.snackbar_text))).setTextColor(ContextCompat.getColor(DeviceOperationActivity.this, R.color.blue_grey_100)); snackbar.show(); } } }
Example 5
Source File: TagDispatcher.java From nordpol with MIT License | 6 votes |
@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 6
Source File: TagDispatcher.java From WalletCordova with GNU Lesser General Public License v2.1 | 6 votes |
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 7
Source File: CardReaderFragment.java From android-CardReader with Apache License 2.0 | 5 votes |
private void enableReaderMode() { Log.i(TAG, "Enabling reader mode"); Activity activity = getActivity(); NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity); if (nfc != null) { nfc.enableReaderMode(activity, mLoyaltyCardReader, READER_FLAGS, null); } }