Added in API level 36

CardEmulation.NfcEventCallback


public static interface CardEmulation.NfcEventCallback

android.nfc.cardemulation.CardEmulation.NfcEventCallback


Callback interface for NFC-related events. These callbacks will be called when registered with CardEmulation.registerNfcEventCallback(java.util.concurrent.Executor, android.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 CardEmulation.unregisterNfcEventCallback(android.nfc.cardemulation.CardEmulation.NfcEventCallback).

Summary

Public methods

default void onAidConflictOccurred(String aid)

This method is called when an AID conflict is detected during an NFC transaction.

default void onAidNotRouted(String aid)

This method is called when an AID is not routed to any service during an NFC transaction.

default void onInternalErrorReported(int errorType)

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

default void onNfcStateChanged(int state)

This method is called when the NFC adapter state changes.

default void onObserveModeStateChanged(boolean isEnabled)

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

default void onPreferredServiceChanged(boolean isPreferred)

This method is called when this package gains or loses preferred NFC service status.

default 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.

Public methods

onAidConflictOccurred

Added in API level 36
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 CardEmulation.setPreferredService(android.app.Activity, android.content.ComponentName) to ensure the transaction is routed to your service.

Parameters
aid String: The AID that is in conflict This value cannot be null.

onAidNotRouted

Added in API level 36
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.

Parameters
aid String: the AID that was not routed This value cannot be null.

onInternalErrorReported

Added in API level 36
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.

Parameters
errorType int: The type of the internal error Value is CardEmulation.NFC_INTERNAL_ERROR_UNKNOWN, CardEmulation.NFC_INTERNAL_ERROR_NFC_CRASH_RESTART, CardEmulation.NFC_INTERNAL_ERROR_NFC_HARDWARE_ERROR, or CardEmulation.NFC_INTERNAL_ERROR_COMMAND_TIMEOUT

onNfcStateChanged

Added in API level 36
public void onNfcStateChanged (int state)

This method is called when the NFC adapter state changes.

Parameters
state int: The new NFC adapter state Value is NfcAdapter.STATE_OFF, NfcAdapter.STATE_TURNING_ON, NfcAdapter.STATE_ON, or NfcAdapter.STATE_TURNING_OFF

onObserveModeStateChanged

Added in API level 36
public void onObserveModeStateChanged (boolean isEnabled)

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

Parameters
isEnabled boolean: true if observe mode has been enabled, false if it has been disabled

onPreferredServiceChanged

Added in API level 36
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 RoleManager.ROLE_WALLET) or the preferred service of the foreground activity, set with CardEmulation.setPreferredService(android.app.Activity, android.content.ComponentName).

Parameters
isPreferred boolean: true is this service has become the preferred NFC service, false if it is no longer the preferred service

onRemoteFieldChanged

Added in API level 36
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.

Parameters
isDetected boolean: true if an NFC reader is detected, false if it is lost