Java Code Examples for android.nfc.NfcAdapter#STATE_TURNING_ON

The following examples show how to use android.nfc.NfcAdapter#STATE_TURNING_ON . 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: RNHceModule.java    From react-native-nfc-hce with Apache License 2.0 6 votes vote down vote up
@Override
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);
        WritableMap payload = Arguments.createMap();
        switch (state) {
            case NfcAdapter.STATE_OFF:
                payload.putBoolean("status", false);
                sendEvent(reactContext, "listenNFCStatus", payload);
                break;
            case NfcAdapter.STATE_TURNING_OFF:
                break;
            case NfcAdapter.STATE_ON:
                payload.putBoolean("status", true);
                sendEvent(reactContext, "listenNFCStatus", payload);
                break;
            case NfcAdapter.STATE_TURNING_ON:
                break;
        }
    }
}
 
Example 2
Source File: WifiNetworkActivity.java    From WiFiKeyShare with GNU General Public License v3.0 6 votes vote down vote up
void initializeNfcStateChangeListener() {
    nfcStateChangeBroadcastReceiver = new BroadcastReceiver() {
        @Override
        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;
                }
            }
        }
    };
}
 
Example 3
Source File: NfcIconData.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(NfcIconData icon, Intent intent) {
    switch (intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF)) {
        case NfcAdapter.STATE_OFF:
        case NfcAdapter.STATE_TURNING_OFF:
            icon.onIconUpdate(-1);
            break;
        case NfcAdapter.STATE_ON:
        case NfcAdapter.STATE_TURNING_ON:
            icon.onIconUpdate(0);
            break;
    }
}
 
Example 4
Source File: NfcManager.java    From smartcard-reader with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action == null)
        return;
    if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
        int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE,
                NfcAdapter.STATE_ON);
        if (state == NfcAdapter.STATE_ON
                || state == NfcAdapter.STATE_TURNING_ON) {
            Log.d(TAG, "state: " + state + " , dialog: "
                    + mEnableNfcDialog);
            if (mEnableNfcDialog != null) {
                mEnableNfcDialog.dismiss();
            }
            if (state == NfcAdapter.STATE_ON) {
                mNfcAdapter
                        .enableReaderMode(
                                mActivity,
                                mReaderCallback,
                                READER_FLAGS,
                                null);
            }
        } else {
            if (mEnableNfcDialog == null || !mEnableNfcDialog.isShowing()) {
                mActivity.showDialog(DIALOG_ENABLE_NFC);
            }
        }
    }
}