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
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

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.
respond(Uint8List response) Future<void>
Answers the APDU most recently delivered to onApduReceived.
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