Example usage for android.nfc NfcAdapter EXTRA_ADAPTER_STATE

List of usage examples for android.nfc NfcAdapter EXTRA_ADAPTER_STATE

Introduction

In this page you can find the example usage for android.nfc NfcAdapter EXTRA_ADAPTER_STATE.

Prototype

String EXTRA_ADAPTER_STATE

To view the source code for android.nfc NfcAdapter EXTRA_ADAPTER_STATE.

Click Source Link

Document

Used as an int extra field in #ACTION_ADAPTER_STATE_CHANGED intents to request the current power state.

Usage

From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java

void initializeNfcStateChangeListener() {
    nfcStateChangeBroadcastReceiver = new BroadcastReceiver() {
        @Override/*from   w  w w.  ja va2  s .  c o m*/
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();

            if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
                final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF);

                switch (state) {
                case NfcAdapter.STATE_OFF:
                case NfcAdapter.STATE_TURNING_OFF:
                    onNfcDisabled();
                    break;
                case NfcAdapter.STATE_TURNING_ON:
                    break;
                case NfcAdapter.STATE_ON:
                    onNfcEnabled();
                    break;
                }
            }
        }
    };
}