scanMdocReader

suspend fun NfcTagReader.scanMdocReader(message: String?, options: MdocTransportOptions, handoverOptions: MdocReaderNfcHandoverOptions, transportFactory: MdocTransportFactory = MdocTransportFactory.Default, selectConnectionMethod: suspend (connectionMethods: List<MdocConnectionMethod>) -> MdocConnectionMethod?, negotiatedHandoverConnectionMethods: List<MdocConnectionMethod>, nfcScanOptions: NfcScanOptions = NfcScanOptions(), context: CoroutineContext = Dispatchers.Default): ScanMdocReaderResult?

Performs NFC engagement as a mdoc reader.

This blocks until a connection has been established and on successful handover a ScanMdocReaderResult instance is returned with the transport, device engagement, handover, and the time spent exchanging APDUs with the remote mdoc.

Return

a ScanMdocReaderResult if successful handover was established, null if the user dismissed the dialog.

Parameters

message

the message to display in the NFC tag scanning dialog or null to not show a dialog. Not all platforms supports not showing a dialog, use org.multipaz.nfc.nfcTagScanningSupportedWithoutDialog to check at runtime if the platform supports this.

options

the MdocTransportOptions used to create new MdocTransport instances.

handoverOptions

the MdocReaderNfcHandoverOptions used to control handover behavior.

transportFactory

the factory used to create MdocTransport instances.

selectConnectionMethod

used to choose a connection method if the remote mdoc is using NFC static handover.

negotiatedHandoverConnectionMethods

the connection methods to offer if the remote mdoc is using NFC Negotiated Handover.

nfcScanOptions

a NfcScanOptions with options to influence scanning.

context

the CoroutineContext to use for calls to the tag which blocks the calling thread.


suspend fun <T> NfcTagReader.scanMdocReader(message: String?, options: MdocTransportOptions, handoverOptions: MdocReaderNfcHandoverOptions, transportFactory: MdocTransportFactory = MdocTransportFactory.Default, selectConnectionMethod: suspend (connectionMethods: List<MdocConnectionMethod>) -> MdocConnectionMethod?, negotiatedHandoverConnectionMethods: List<MdocConnectionMethod>, nfcScanOptions: NfcScanOptions = NfcScanOptions(), context: CoroutineContext = Dispatchers.Default, onHandover: suspend (scanResult: ScanMdocReaderResult) -> T?): T?

Performs NFC engagement and reader transaction processing as a mdoc reader.

Use this variant when performing reader transactions where the data transfer should be handled inline with NFC scanning.

For NFCv2 NFC-only engagements (MdocConnectionMethodNfcV2), onHandover is invoked while the NFC scanning UI dialog remains active. If the holder removes their device prematurely or a transport error occurs before onHandover returns a response, scanMdocReader closes the failed transport, keeps the scanner dialog visible, and continues polling for tag re-taps. When a re-tap occurs, onHandover is invoked again with the new engagement's ScanMdocReaderResult to complete the transaction.

For all other engagement types (e.g. NFCv2 with BLE, NFC Negotiated Handover, or NFC Static Handover), the NFC scanning dialog is dismissed immediately upon first tap handover, and onHandover is executed after the dialog has been removed.

Return

the non-null result of type T returned by onHandover when the transaction completes successfully, or null if the user dismissed the NFC scanning dialog.

Parameters

message

the message to display in the NFC tag scanning dialog or null to not show a dialog. Not all platforms support not showing a dialog, use org.multipaz.nfc.nfcTagScanningSupportedWithoutDialog to check at runtime if the platform supports this.

options

the MdocTransportOptions used to create new MdocTransport instances.

handoverOptions

the MdocReaderNfcHandoverOptions used to control handover behavior.

transportFactory

the factory used to create MdocTransport instances.

selectConnectionMethod

used to choose a connection method if the remote mdoc is using NFC static handover.

negotiatedHandoverConnectionMethods

the connection methods to offer if the remote mdoc is using NFC Negotiated Handover.

nfcScanOptions

a NfcScanOptions with options to influence scanning.

context

the CoroutineContext to use for calls to the tag which blocks the calling thread.

onHandover

callback invoked with the ScanMdocReaderResult upon handover completion. For NFCv2 NFC-only engagements, this executes inside the active tag scanning loop to support re-taps on disconnect. For all other handover types, it is invoked after the scanning dialog has been dismissed.