Example usage for android.nfc NfcAdapter ACTION_ADAPTER_STATE_CHANGED

List of usage examples for android.nfc NfcAdapter ACTION_ADAPTER_STATE_CHANGED

Introduction

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

Prototype

String ACTION_ADAPTER_STATE_CHANGED

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

Click Source Link

Document

Broadcast Action: The state of the local NFC adapter has been changed.

Usage

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.FixturesFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fixtures_layout, container, false);
    ButterKnife.inject(this, view);
    buildGoogleApiClient();/*from   w  w  w.jav  a 2 s  . com*/

    //Registering events to detect radio changes
    final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();
            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
                updateBluetoothStatusDisplay();
            } else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
                updateWifiStatusDisplay();
            } else if (action.equals(LocationManager.PROVIDERS_CHANGED_ACTION)) {
                updateGPSStatusDisplay();
            } else if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
                updateNFCStatusDisplay();
            }
        }
    };
    IntentFilter filter = new IntentFilter();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        filter.addAction(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
    }

    filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
    filter.addAction(LocationManager.PROVIDERS_CHANGED_ACTION);

    updateWifiStatusDisplay();
    updateBluetoothStatusDisplay();
    updateGPSStatusDisplay();
    updateNFCStatusDisplay();
    getActivity().registerReceiver(receiver, filter);
    return view;
}

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

void initializeNfcStateChangeListener() {
    nfcStateChangeBroadcastReceiver = new BroadcastReceiver() {
        @Override/*w  ww.  j av  a2 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;
                }
            }
        }
    };
}

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

@Override
protected void onResume() {
    super.onResume();
    if (isNfcAvailable()) {
        IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
        registerReceiver(nfcStateChangeBroadcastReceiver, filter);
        startForegroundDispatch();//from  ww  w  . j  av a 2s  . c o  m
    }
}