CardEmulation.NfcEventCallback


public static interface CardEmulation.NfcEventCallback

android.nfc.cardemulation.CardEmulation.NfcEventCallback


Listener for preferred service state changes.

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 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, either 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)

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

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

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

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

public void onNfcStateChanged (int state)

This method is called when the NFC state changes.

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

onObserveModeStateChanged

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

public void onPreferredServiceChanged (boolean isPreferred)

This method is called when this package gains or loses preferred Nfc service status, either 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

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