HostCardEmulation class
Host card emulation: the phone answers a reader as if it were a contactless card.
Android only. Apple's equivalent is gated behind an entitlement that is not generally available, so there is no iOS counterpart and these calls throw there.
HostCardEmulation.instance.onApduReceived = (apdu) {
// Answer a SELECT with 9000, anything else with 6D00.
final isSelect = apdu.length > 1 && apdu[1] == 0xA4;
HostCardEmulation.instance.respond(
Uint8List.fromList(isSelect ? [0x90, 0x00] : [0x6D, 0x00]),
);
};
await HostCardEmulation.instance.registerAids(['F0010203040506']);
What "foreground" means here
The Android service that receives APDUs can be started while the app's Flutter engine is not running. This release bridges APDUs only while the engine is alive; a tap with the app fully stopped is answered with a "not supported" status word rather than being queued. An app that must work while closed needs the background engine, which is not in this release.
Call setPreferredService with true while your app is on screen, or a tap can be routed to the user's default wallet instead.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- onApduReceived ← void Function(Uint8List apdu)?
-
A reader sent a command APDU. Answer it with respond.
no getter
- onDeactivated ← void Function(int reason)?
-
The link to the reader ended.
no getter
-
onPollingFrames
← void Function(List<
PollingFrame> frames)? -
Frames from the reader's polling loop, while observe mode is on.
no getter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
isObserveModeEnabled(
) → Future< bool> - Whether observe mode is on right now.
-
isObserveModeSupported(
) → Future< bool> - Whether this device can observe a reader's polling loop.
-
isSupported(
) → Future< bool> - Whether the device supports host card emulation at all.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerAids(
List< String> aids) → Future<bool> - Registers the application identifiers this app answers for, as uppercase hex.
-
registerPollingLoopFilter(
{required String filter, bool autoTransact = false}) → Future< bool> -
Delivers polling frames whose bytes are exactly
filter, as uppercase hex. -
registerPollingLoopPatternFilter(
{required String pattern, bool autoTransact = false}) → Future< bool> -
As registerPollingLoopFilter, but
patternmatches a family of frames. -
removePollingLoopFilter(
String filter) → Future< bool> - Removes a filter added by registerPollingLoopFilter.
-
removePollingLoopPatternFilter(
String pattern) → Future< bool> - Removes a filter added by registerPollingLoopPatternFilter.
-
respond(
Uint8List response) → Future< void> - Answers the APDU most recently delivered to onApduReceived.
-
setDefaultToObserveMode(
bool shouldDefault) → Future< bool> - Whether the emulation service should come up in observe mode whenever it becomes the preferred service, instead of needing setObserveModeEnabled on every foreground.
-
setObserveModeEnabled(
bool enabled) → Future< bool> - Stops the device answering readers, and starts reporting their polling frames to onPollingFrames instead.
-
setPreferredService(
bool preferred) → Future< void> - Makes this app the preferred handler while it is in the foreground.
-
toString(
) → String -
A string representation of this object.
inherited
-
unregisterAids(
) → Future< bool> - Drops every AID registered by registerAids and disables the emulation service again, taking the app back out of the system's card-emulation registry.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → HostCardEmulation
-
no setter