start

fun start(options: ChipReadOptions, adapter: NfcAdapter?, observer: ChipReadObserver, settings: NfcReadSettings = NfcReadSettings()): NfcChipRead

Starts a read whose reader mode your app runs. Returns at once; the read waits for reader mode to hand it a document: pass it to NfcReaderMode.enable. The parameters come in the order of the Activity-owning start: what to read, then the observer, then the settings.

Return

The read: the reader-mode callback, and the handle to cancel it.

Since

1.0.0

Parameters

options

The key, the data groups, the roots and the check time.

adapter

The device's NFC adapter, from NfcAdapter.getDefaultAdapter(context); null (no NFC on the device) ends the read with ChipReadEnding.NotStarted.

observer

Gets every update and exactly one ending.

settings

What to do after a lost link, and the time limits.


fun start(activity: Activity, options: ChipReadOptions, observer: ChipReadObserver, settings: NfcReadSettings = NfcReadSettings()): NfcChipRead

Starts a read that owns reader mode: the high-level way to read a chip on Android. Returns at once. It checks that NFC can be used, turns reader mode on for activity with the SDK's flags and NfcReadSettings.presenceCheckDelayMillis, runs the read, and turns reader mode off at the ending, on every ending and before the observer hears it. Reader mode is never switched while a document may be on the phone: once on at the start, once off at the end.

Call it on the main thread, with the Activity that shows the read, from a person's action (for example a button), not from onCreate.

A rotation ends the read. The read is for this one Activity. When the Activity is destroyed and made again (a rotation or any other configuration change), the read ends at once as ChipReadEnding.EndedBySystem with NfcUnavailable.Reason.ACTIVITY_DESTROYED and the key is cleared. Starting it again needs a new key and spends another authentication attempt with the chip. Two ways to avoid it: declare android:configChanges for the orientation and size of the read screen, so the Activity is not destroyed, or lock the orientation while the read runs. A read that was not started from a person's action but from onCreate also starts again after every rotation, so start it from a button.

When the read cannot start it ends at once as ChipReadEnding.NotStarted with a typed reason: NfcUnavailable.Reason.ACTIVITY_DESTROYED for an Activity that is finishing or destroyed, NOT_SUPPORTED, DISABLED, NOT_PERMITTED or REQUEST_REFUSED as NfcReaderMode.enable reports them, and READ_IN_PROGRESS for a second read at once. The SDK does not ask whether activity is resumed: the platform applies reader mode when it resumes. See the class documentation for a pause in the middle of a read. The read holds activity weakly and lets it go at the ending.

By default (NfcReadSettings.observerOn is ObserverThread.MAIN) the observer is called on the main thread and hears nothing before this call returns. With ObserverThread.CALLER the updates come from the read's own thread, and io.lightine.tessera.emrtd.ChipReadState.Starting, and the ending of a read that cannot start, can come before this call returns; the ending still comes on the main thread, where the read turns reader mode off first.

Return

The read, to cancel it. It is also the reader-mode callback, already registered: do not pass it to NfcReaderMode.enable.

Since

1.0.0

Parameters

activity

The read screen, shown now.

options

The key, the data groups, the roots and the check time. The read takes the key over and clears it at the ending.

observer

Gets every update and exactly one ending.

settings

What to do after a lost link, the time limits, reader mode and the observer's thread. Your app's own reader mode. An Activity has one reader mode: this start replaces any reader mode your app turned on for activity (its callback hears no tag during the read), and the ending turns reader mode off for activity. The platform has no call that tells whether an Activity already has reader mode on, so the SDK cannot report it: turn your own reader mode off before the read, and on again after its ending if you need it.