Skip to main content

NFC reading

Reading the document chip gives you the data and the portrait signed by the issuing state — the highest level of document assurance available remotely. MobbScan reads the chip of e-passports and Spanish ID cards (DNI v3).

Before you begin
  • Add the mobbscan-nfc-extension-android module and the NFC permission. See Installation.
  • Start a process to get a scanId.
  • Get the chip access data. The easiest way is a document scan first: it returns the document number, date of birth and date of expiry.

1. Configure the reader​

Configure NfcDocumentReader with a progress listener and a result listener:

val extractFace = true // also read the chip portrait

NfcDocumentReader.getInstance().configureService(activity, extractFace, object : OnNfcDocumentReaderFinish {
override fun onScanSuccess(scanResultData: MobbScanScanResultData) {
// Chip data, as in a document scan result
}
override fun onScanFailed(error: NfcError) {
// Reading failed: ask the user to try again
}
}) { nfcEvent, progress ->
// Update the progress UI
}

Reading the portrait makes the process slower; set extractFace to false if you do not need it.

2. Start reading​

Ask the user to hold the phone against the document, then start the reader with the access data:

// Passports and DNI v3: data from the MRZ
NfcDocumentReader.getInstance().readDocumentNFC(documentNumber, dateOfBirth, dateOfExpiry)

// DNI v3 only: the 6-digit card access number (CAN) printed on the card
NfcDocumentReader.getInstance().readDocumentNFC(canNumber)

Progress events​

Chip reading takes a few seconds and the phone must not move. Use the events to keep the user informed:

NFCEventMeaningSuggested message
CONFIGURING_SERVICEThe reader is getting ready"Hold your phone against the document"
AUTHENTICATINGThe access key is being verified"Don't move the document"
READING_DATAPersonal data is being read"Reading data…"
READING_IMAGEThe portrait is being read"Almost done…"

progress gives the completion percentage, useful for a progress bar.

Result​

onScanSuccess returns a MobbScanScanResultData, the same object as a document scan, with the data read from the chip. onScanFailed returns an NfcError; the usual causes are the phone moving away from the document or wrong access data.

The SDK sample app includes a complete NFC flow.