Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

# CardEmulation.NfcEventCallback

*** ** * ** ***


`
public
static


interface
CardEmulation.NfcEventCallback
`


`


`

|---|
| android.nfc.cardemulation.CardEmulation.NfcEventCallback |

<br />

*** ** * ** ***

Callback interface for NFC-related events.

These callbacks will be called when registered with
`https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#registerNfcEventCallback(java.util.concurrent.Executor,%20android.nfc.cardemulation.CardEmulation.NfcEventCallback)` and while the registered caller
is still alive. When you are done listening to the callbacks, you should unregister it with
`https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#unregisterNfcEventCallback(android.nfc.cardemulation.CardEmulation.NfcEventCallback)`.

## Summary

| ### Public methods ||
|---|---|
| ` default void` | ` https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.NfcEventCallback#onAidConflictOccurred(java.lang.String)(https://developer.android.com/reference/java/lang/String aid) ` This method is called when an AID conflict is detected during an NFC transaction. |
| ` default void` | ` https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.NfcEventCallback#onAidNotRouted(java.lang.String)(https://developer.android.com/reference/java/lang/String aid) ` This method is called when an AID is not routed to any service during an NFC transaction. |
| ` default void` | ` https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.NfcEventCallback#onInternalErrorReported(int)(int errorType) ` This method is called when an internal error is reported by the NFC stack. |
| ` default void` | ` https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.NfcEventCallback#onNfcStateChanged(int)(int state) ` This method is called when the NFC adapter state changes. |
| ` default void` | ` https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.NfcEventCallback#onObserveModeStateChanged(boolean)(boolean isEnabled) ` This method is called when observe mode has been enabled or disabled. |
| ` default void` | ` https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.NfcEventCallback#onOffHostAidSelected(java.lang.String,%20java.lang.String)(https://developer.android.com/reference/java/lang/String aid, https://developer.android.com/reference/java/lang/String offHostSecureElement) ` This method is called when an off-host AID is selected. |
| ` default void` | ` https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.NfcEventCallback#onPreferredServiceChanged(boolean)(boolean isPreferred) ` This method is called when this package gains or loses preferred NFC service status. |
| ` default void` | ` https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation.NfcEventCallback#onRemoteFieldChanged(boolean)(boolean isDetected) ` This method is called when the NFC controller is in card emulation mode and an NFC reader's field is either detected or lost. |

## Public methods

### onAidConflictOccurred

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onAidConflictOccurred (String aid)
```

This method is called when an AID conflict is detected during an NFC transaction. This
can happen when multiple services are registered for the same AID. If your service is
registered for this AID you may want to instruct users to bring your app to the
foreground and ensure you call `https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#setPreferredService(android.app.Activity,%20android.content.ComponentName)`
to ensure the transaction is routed to your service.

<br />

| Parameters ||
|---|---|
| `aid` | `String`: The AID that is in conflict. This value cannot be `null`. <br /> |

### onAidNotRouted

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onAidNotRouted (String aid)
```

This method is called when an AID is not routed to any service during an NFC
transaction. This can happen when no service is registered for the given AID.

<br />

| Parameters ||
|---|---|
| `aid` | `String`: the AID that was not routed. This value cannot be `null`. <br /> |

### onInternalErrorReported

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onInternalErrorReported (int errorType)
```

This method is called when an internal error is reported by the NFC stack.

No action is required in response to these events as the NFC stack will automatically
attempt to recover. These errors are reported for informational purposes only.

Note that these errors can be reported when performing various internal NFC operations
(such as during device shutdown) and cannot always be explicitly correlated with NFC
transaction failures.

<br />

| Parameters ||
|---|---|
| `errorType` | `int`: The type of the internal error. Value is one of the following: - `https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#NFC_INTERNAL_ERROR_UNKNOWN` - `https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#NFC_INTERNAL_ERROR_NFC_CRASH_RESTART` - `https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#NFC_INTERNAL_ERROR_NFC_HARDWARE_ERROR` - `https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#NFC_INTERNAL_ERROR_COMMAND_TIMEOUT` |

### onNfcStateChanged

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onNfcStateChanged (int state)
```

This method is called when the NFC adapter state changes.

<br />

| Parameters ||
|---|---|
| `state` | `int`: The new NFC adapter state. Value is one of the following: - `https://developer.android.com/reference/android/nfc/NfcAdapter#STATE_OFF` - `https://developer.android.com/reference/android/nfc/NfcAdapter#STATE_TURNING_ON` - `https://developer.android.com/reference/android/nfc/NfcAdapter#STATE_ON` - `https://developer.android.com/reference/android/nfc/NfcAdapter#STATE_TURNING_OFF` |

### onObserveModeStateChanged

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onObserveModeStateChanged (boolean isEnabled)
```

This method is called when observe mode has been enabled or disabled.

<br />

| Parameters ||
|---|---|
| `isEnabled` | `boolean`: true if observe mode has been enabled, false if it has been disabled <br /> |

### onOffHostAidSelected

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void onOffHostAidSelected (String aid, 
                String offHostSecureElement)
```

This method is called when an off-host AID is selected.

This indicates that an offhost (Secure Element or UICC) transaction
has started.

<br />

| Parameters ||
|---|---|
| `aid` | `String`: The AID that was selected. This value cannot be `null`. <br /> |
| `offHostSecureElement` | `String`: Secure Element on which the AID was routed to. Will be string with prefix SIM or prefix eSE (`https://developer.android.com/reference/android/se/omapi/Reader#getName()`). Ref: GSMA TS.26 - NFC Handset Requirements TS26_NFC_REQ_069: For UICC, Secure Element Name SHALL be SIM\[smartcard slot\] (e.g. SIM/SIM1, SIM2\\u2026 SIMn). TS26_NFC_REQ_070: For embedded SE, Secure Element Name SHALL be eSE\[number\] (e.g. eSE/eSE1, eSE2, etc.). This value cannot be `null`. <br /> |

### onPreferredServiceChanged

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onPreferredServiceChanged (boolean isPreferred)
```

This method is called when this package gains or loses preferred NFC service status.
This can happen by way of either it becoming the default wallet role holder
(see `https://developer.android.com/reference/android/app/role/RoleManager#ROLE_WALLET`) or the preferred service of the
foreground activity, set with `https://developer.android.com/reference/android/nfc/cardemulation/CardEmulation#setPreferredService(android.app.Activity,%20android.content.ComponentName)`.

<br />

| Parameters ||
|---|---|
| `isPreferred` | `boolean`: true is this service has become the preferred NFC service, false if it is no longer the preferred service <br /> |

### onRemoteFieldChanged

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onRemoteFieldChanged (boolean isDetected)
```

This method is called when the NFC controller is in card emulation mode and an NFC
reader's field is either detected or lost.

<br />

| Parameters ||
|---|---|
| `isDetected` | `boolean`: true if an NFC reader is detected, false if it is lost <br /> |