Migrate to v2
This guide lists the changes you need to make in your Android app to move from v1 to v2 of the Android SDK.
The SDK no longer creates transactions: your backend does, and passes the result to your app. Before you update the SDK, update your backend as described in the Platform migration guide, in particular No proxy and Consent.
Installation
The artifact is unchanged: com.microblink:microblink-platform, from the same Maven repository. Update its version to 2.0.0, through the new BOM, and add the scanning SDKs that your workflows need:
dependencies {
implementation(platform("com.microblink:microblink-platform-bom:2.0.0"))
implementation("com.microblink:microblink-platform")
// Only the ones your workflows need:
implementation("com.microblink:blinkid-verify-ux") // document scanning and document verification
implementation("com.microblink:blinkcard-ux") // card scanning
implementation("com.microblink:biometrics-ux") // face capture
}
In v1, the SDK brought in the scanning SDKs.
In v2, your app adds them, without a version, so that the BOM sets it.
If a workflow has a step whose scanning SDK your app doesn't include, the verification fails with EngineError.MissingScannerSdk.
The SDK brings in the new com.microblink:microblink-platform-engine artifact, which contains the engine.
Don't add it separately, unless you want to build your own UI on the engine alone.
The minimum Android version is now Android 8.0 (API level 26), up from Android 7.0 (API level 24).
Starting a verification
The entry point is unchanged: you call MicroblinkPlatform.startVerification, and the SDK opens a separate activity for the verification screens.
What changes is the configuration you pass to it.
Instead of a workflow ID, proxy settings, and consent, you pass the sdkConfiguration your backend got when it created the transaction.
- v1
- v2
MicroblinkPlatform.startVerification(
activity = this,
configuration = MicroblinkPlatformConfig(
mbpResultListener = object : MicroblinkPlatformResultListener {
override fun onVerificationFinished(mbpResult: MicroblinkPlatformResult) {
Log.d("MBP", "Transaction ${mbpResult.transactionId}: ${mbpResult.state}")
}
override fun onVerificationCanceled(cancelState: MicroblinkPlatformCancelState) {
Log.d("MBP", "User canceled: ${cancelState.cancelReason}")
}
},
mbpServiceSettings = MicroblinkPlatformServiceSettings(
workflowId = "ID of the workflow to use",
proxySettings = MicroblinkPlatformProxySettings(
url = "URL of your proxy service"
),
consent = MicroblinkPlatformConsent(
userId = "unique user ID",
isProcessingStoringAllowed = true,
givenOn = System.currentTimeMillis()
)
)
)
)
// sdkConfiguration is the value your backend got from POST /api/v2/transaction.
MicroblinkPlatform.startVerification(
activity = this,
configuration = MicroblinkPlatformConfiguration(
engine = EngineConfiguration(
service = ServiceSettings(sdkConfiguration = sdkConfiguration)
),
resultListener = object : MicroblinkPlatformResultListener {
override fun onVerificationFinished(outcome: SessionOutcome.Verification) {
Log.d("MBP", "Transaction ${outcome.transactionId}: ${outcome.state}")
}
override fun onVerificationCanceled(outcome: SessionOutcome.Canceled) {
Log.d("MBP", "User canceled: ${outcome.reason}")
}
override fun onVerificationFailed(transactionId: String?, error: EngineError) {
Log.d("MBP", "Verification failed: $error")
}
}
)
)
Configuration fields
Here's the whole configuration in v1 and in v2:
- v1
- v2
MicroblinkPlatformConfig(
mbpResultListener = resultListener,
mbpServiceSettings = MicroblinkPlatformServiceSettings(
workflowId = "...",
proxySettings = MicroblinkPlatformProxySettings(
url = "...",
startTransactionPath = "/transaction",
cancelWorkflowPath = "/initialize/{workflowId}/cancel",
workflowInfoPath = "/initialize/{workflowId}/info",
additionalRequestHeaders = emptyMap(),
),
consent = MicroblinkPlatformConsent(
userId = "...",
isProcessingStoringAllowed = true,
isTrainingAllowed = false,
givenOn = System.currentTimeMillis(),
),
correlationId = null,
),
mbpUiSettings = MicroblinkPlatformUiSettings(
colorScheme = colorScheme,
typography = MicroblinkPlatformTypography.default(),
mbpImages = MicroblinkPlatformImages(),
buttonShape = ButtonShape(CircleShape),
documentScanningTypography = documentScanningTypography,
),
mbpCardScanResultListener = cardScanResultListener,
)
MicroblinkPlatformConfiguration(
engine = EngineConfiguration(
service = ServiceSettings(
sdkConfiguration = "...",
retryPolicy = NetworkRetryPolicy(),
),
),
resultListener = resultListener,
ui = UiConfiguration(
colorScheme = colorScheme,
typography = MicroblinkPlatformTypography.default(),
scannerTypography = ScannerTypography(),
images = MicroblinkPlatformImages(),
buttonShape = CircleShape,
),
cardScanResultListener = cardScanResultListener,
)
MicroblinkPlatformConfig is renamed to MicroblinkPlatformConfiguration, and its fields lose the mbp prefix:
mbpServiceSettingsis replaced byengine.mbpResultListeneris renamed toresultListener.mbpUiSettingsis renamed toui.mbpCardScanResultListeneris renamed tocardScanResultListener.
Service settings
MicroblinkPlatformServiceSettings is replaced by EngineConfiguration(service = ServiceSettings(sdkConfiguration)).
Here's what happened to each of its fields:
workflowIdis removed. Your backend sets the workflow when it creates the transaction.proxySettingsis removed, together withMicroblinkPlatformProxySettingsand its URL, custom paths, andadditionalRequestHeaders. The SDK talks to the Platform directly.consentis removed, together withMicroblinkPlatformConsent. Collect the consent in your app before the verification starts; your backend sends it when it creates the transaction. The SDK's consent dialog is removed as well, so any overrides of itsmbp_consent_dialog_*string resources no longer have an effect.correlationIdis removed. Your backend sends it when it creates the transaction, in thecorrelationIdfield ofPOST /api/v2/transaction.ServiceSettingshas a new optionalretryPolicy, which controls how often the SDK retries a failed or busy request. The default,NetworkRetryPolicy(maxAttempts = 5, retryDelayMillis = 500), is a good fit for most apps.
UI settings
MicroblinkPlatformUiSettings is renamed to UiConfiguration, with these changes:
colorSchemeis unchanged, but itsprimary,onPrimary,surface, andonSurfacecolors now also color the document scanning, card scanning, and face capture screens.typographystill takes aMicroblinkPlatformTypography, but its fields have changed. Instead of v1's field for each screen (homeTitle,errorTitle, and so on), it has a field for each kind of text, such asheading,description,fieldBody, andbutton. See the KDoc ofMicroblinkPlatformTypography, or Fonts, for which style goes where. To keep our default sizes and only change the font, useMicroblinkPlatformTypography.default(fontFamily = yourFontFamily).mbpImagesis renamed toimages.MicroblinkPlatformImagesis unchanged.buttonShapetakes aShapedirectly, instead of aButtonShapewrapper. It now applies to every button on our screens, including those in dialogs.documentScanningTypographyis replaced byscannerTypography, which takes aScannerTypography. It sets the fonts of the document scanning, card scanning, and face capture screens; read Scanning screens.
Results
MicroblinkPlatformResultListener has a new method, onVerificationFailed(transactionId, error), which you must implement.
It's called when the verification ends with an error that the user can't retry, after they close the error screen.
transactionId is null if the verification couldn't start at all.
Exactly one of the three methods is called for each verification, on the main thread, after the user leaves our screens. The other two methods take new types:
onVerificationFinishedreceives aSessionOutcome.Verificationinstead of aMicroblinkPlatformResult. It has the sametransactionIdandstatefields;stateis now aVerificationState(Accept,Reject, orReview).onVerificationCanceledreceives aSessionOutcome.Canceledinstead of aMicroblinkPlatformCancelState.cancelReasonis renamed toreason, and theConsentDeniedreason is removed, because the SDK no longer handles consent.transactionIdis no longer nullable.
If you use MicroblinkPlatformCardScanResultListener:
onCardScannedstill receives aCardScanResult, but itsexpiryDateis now aCardDateinstead of aDate, with the sameday,month, andyearfields.- It's called at most once for each verification, as soon as the Platform accepts the card.
The result is complete, but its
toString()hides most of the card number, the owner, and the CVV, so that logging it doesn't leak the card.
Lifecycle
-
startVerificationnow throws anIllegalStateExceptionif a verification is already running. -
If the app's process is killed during a verification, the verification can't continue. Create a new transaction and start over.
-
The SDK uses AndroidX App Startup to track which activity is in front, and starts automatically. If your app turns off App Startup's automatic initialization, or runs the verification in a separate process, initialize the SDK in
Application.onCreateinstead, before any activity starts:AppInitializer.getInstance(this).initializeComponent(EngineInitializer::class.java)