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).
- Add the
mobbscan-nfc-extension-androidmodule 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:
- Kotlin
- Java
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
}
boolean extractFace = true; // also read the chip portrait
NfcDocumentReader.getInstance().configureService(activity, extractFace, new OnNfcDocumentReaderFinish() {
@Override
public void onScanSuccess(MobbScanScanResultData scanResultData) {
// Chip data, as in a document scan result
}
@Override
public void onScanFailed(NfcError error) {
// Reading failed: ask the user to try again
}
}, new OnNfcEvent() {
@Override
public void onEvent(NFCEvent nfcEvent, int 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:
- Kotlin
- Java
// 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)
// 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:
NFCEvent | Meaning | Suggested message |
|---|---|---|
CONFIGURING_SERVICE | The reader is getting ready | "Hold your phone against the document" |
AUTHENTICATING | The access key is being verified | "Don't move the document" |
READING_DATA | Personal data is being read | "Reading data…" |
READING_IMAGE | The 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.