How to build an Android application that can present a credential via the DC API
Digital Credentials (DC) API support is currently offered as an open preview. The DC API specification itself is still under active development in the W3C Web Incubator CG, and platform implementations continue to evolve. As such, functionality may be limited, may not work in all scenarios, and could change or break without prior notice as browsers and operating systems update their implementations.
Overview
This guide demonstrates how to use the Holder SDK to build an Android application that can present a claimed mDoc to a verifier remotely via the DC API, as per Appendix A of OpenID4VP 1.0.
Prerequisites
Application base
This guide builds on the knowledge gained in the Claim a credential and Remote presentation tutorials.
It is recommended to complete those tutorials first, then return here to add support for the DC API workflow. To try this guide quickly, skip the tutorials and start from the Holder SDK quickstart sample app instead. It is the completed tutorial app for iOS, Android, and React Native.
Testing Devices
- Mobile device:
- Android device running Android 14 or later.
- The device must have a holder application with claimed credentials set up as per the Claim a credential tutorial or the Holder SDK quickstart, and support for the DC API enabled as per the instructions in this guide.
- Desktop device with a web browser that supports the DC API:
- Chrome or a Chromium based browser v138 or later.
- Safari v26 or later.
How it works
The DC API is a browser standard that enables web applications to request and verify digital credentials directly from compatible wallet applications on the user's device. This provides a seamless user experience where credential presentation happens entirely within the browser context.
From a holder application point of view, there are several changes required to support remote presentations via the DC API compared to the standard OID4VP remote presentation workflow:
- When the DC API feature is enabled upon initialization, all claimed credentials are automatically registered with the Digital Credentials Manager (DCM), making them available when a website requests credentials of matching types.
- When a user selects to present a credential from the holder application, the SDK handles the entire interaction in the background by:
- Receiving the presentation request from the operating system via the DCM.
- Locating the requested credential.
- Authenticating the user via the operating system's native authentication mechanisms (fingerprint recognition, face recognition, or PIN code as defined for the credential).
- Creating and returning the credential presentation to the DCM, which then continues the interaction with the browser without the holder application needing to be directly involved in the process.
On Android, the holder selects the wallet and the credential in a single mandatory screen whose look and behavior are defined by the operating system. Your application decides which data populates this overlay, but not its layout. Unlike iOS, Android does not restrict which credential types can be requested. For the platform-agnostic view of this, see How the credential picker differs on iOS and Android.
Adjusting your mobile application to support remote presentations via the DC API
The Holder SDK handles most of the complexity of the DC API workflow internally. You will have to make the following adjustments to enable it in your application:
- Initialize the SDK with support for the DC API enabled.
- Handle callbacks for verifier authentication (optional).
Initialize the SDK with support for the DC API enabled
When you initialize the SDK with the DC API feature enabled, the SDK automatically:
- Registers your application as a credential provider with the Android operating system
- Registers all claimed credentials with the Digital Credentials Manager (DCM)
- Handles incoming presentation requests
Adjust your SDK initialization code to enable DC API support by setting the enabled flag to true in the DcmConfiguration:
MobileCredentialHolder.getInstance().initialize(
context,
platformConfiguration = platformConfiguration,
dcmConfiguration = DcmConfiguration(enabled = true)
)Handle verifier authentication results (optional)
The SDK provides an API to detect if the Verifier can be trusted. This is an optional step as the SDK will handle the presentation flow and user authentication with the operating system in the background without any involvement from the app. However, if your application has specific requirements around when verifier authentication should be required, you can use this API to enforce that.
Only add these intent filters if your app returns a decision for every request. Once your app
declares them, the SDK opens your activity and waits for its result before it continues. If the
activity does not call setResult() and finish(), the presentation stays on a loading screen and
never completes. If you skip this step, the SDK presents the credential without asking your app.
Perform the following steps to implement verifier authentication in your application:
-
Create a new activity in your app's package, for example
CredentialManagerActivity.kt. This is a separate activity from yourMainActivity. The SDK launches it during a DC API presentation when it needs your app's decision, and continues or cancels the presentation based on the result the activity returns. -
Declare the new activity inside the
applicationelement of yourAndroidManifest.xmlfile, with the following intent filters so it can receive the verifier authentication result from the SDK:
<activity
android:name=".CredentialManagerActivity"
android:exported="false">
<intent-filter>
<action android:name="global.mattr.credentialmanager.action.CONFIRMATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="global.mattr.credentialmanager.action.ERROR" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>These are both optional intent filters. The first one allows your application to receive the verifier authentication result when the verifier is trusted or untrusted but signed. The second one allows your application to receive a callback when an error occurs during the authentication process. If you choose not to implement these intent filters, the SDK will still handle the presentation flow and user authentication with the operating system in the background without any involvement from your app. The SDK launches the activity from within your app, so it does not need to be exported.
- In the
onCreatemethod of the new activity, read the verifier authentication result from the incoming intent:
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.core.content.IntentCompat
import global.mattr.mobilecredential.holder.issuance.dto.VerifierAuthenticationResult
class CredentialManagerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val verifierAuthenticationResult: VerifierAuthenticationResult? = when (intent.action) {
"global.mattr.credentialmanager.action.CONFIRMATION" -> {
IntentCompat.getParcelableExtra(
intent,
"global.mattr.credentialmanager.extra.verifier_authentication_result",
VerifierAuthenticationResult::class.java
)
}
"global.mattr.credentialmanager.action.ERROR" -> null
else -> {
finish()
return
}
}
// Handle the verifier authentication result (next step)
}
}This code example retrieves the verifier authentication result from the incoming intent when the action is global.mattr.credentialmanager.action.CONFIRMATION. If the action is global.mattr.credentialmanager.action.ERROR, it sets the result to null, indicating that an error occurred during the authentication process.
- Handle the result of the Verifier authentication based on your requirements, by replacing the
// Handle the verifier authentication result (next step)comment inonCreate. Every path must end withsetResult()andfinish(). Set the activity result toRESULT_OKto let the SDK continue the presentation, or toRESULT_CANCELEDto decline it. The following example returns success straight away for trusted verifiers, and asks the user to confirm untrusted or unsigned requests:
when (verifierAuthenticationResult) {
is VerifierAuthenticationResult.Trusted -> {
// The verifier is trusted, so continue the presentation
setResult(RESULT_OK)
finish()
}
is VerifierAuthenticationResult.Untrusted, is VerifierAuthenticationResult.Unsigned -> {
setContent {
MaterialTheme {
AlertDialog(
onDismissRequest = {
setResult(RESULT_CANCELED)
finish()
},
title = { Text("Share your credential?") },
text = { Text("This verifier could not be verified as trusted.") },
confirmButton = {
TextButton(onClick = {
setResult(RESULT_OK)
finish()
}) { Text("Share") }
},
dismissButton = {
TextButton(onClick = {
setResult(RESULT_CANCELED)
finish()
}) { Text("Decline") }
}
)
}
}
}
null -> {
// An error occurred during the presentation. The SDK has already cancelled it.
setResult(RESULT_CANCELED)
finish()
}
}This example uses the following additional imports:
import androidx.activity.compose.setContent
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButtonThe confirmation activity runs in your app's main process, while the SDK's DC API activity runs in a
separate <your application ID>.credentialmanager process. When you debug a presentation, include
both processes in your Logcat filter.
Test the application
Let's test that the application is working as expected in both workflows.
Same-device workflow
- Use a browser on your testing mobile device to navigate to the MATTR Labs Verify Credentials tool.
- Select Digital Credentials API from the Select Experience list.
- Select Request credentials.
- Confirm interacting with the verifier on your mobile device when prompted by the operating system (this might look different based on the device and operating system version).
- Select the credential you wish to send to the verifier from the list of credentials suggested by the operating system.
- Send the response.
- The UI prompt will close, and you should see a successful verification indication in the browser where you initiated the request.
Cross-device workflow
- Use a desktop browser to navigate to the MATTR Labs Verify Credentials tool.
- Select Digital Credentials API from the Select Experience list.
- Select Request credentials.
- Open the camera on your testing device and scan the QR code.
- Confirm interacting with the verifier on your mobile device when prompted by the operating system (this might look different based on the device and operating system version).
- Select the credential you wish to send to the verifier from the list of available credentials suggested by the operating system.
- Send the response.
- The UI prompt will close.
- Back on your desktop browser, you should see a successful verification indication.
Summary
You have just used the Android Holder SDK to build an Android application that can present a claimed mDoc to a verifier remotely via the DC API, as per Appendix A of OpenID4VP 1.0.
This was achieved by making the following adjustments to your application:
- Initialize the SDK with support for the DC API enabled.
- Optionally, handle the verifier's authentication result.
What's next?
- You can localize the credential picker so the credential title, subtitle, and claim labels are shown in the user's language.
- You can build a web application that will interact with your wallet application via an online presentation workflow using the DC API.
- You can build additional capabilities into your new application:
- Present a claimed mDoc for verification via a proximity presentation workflow.
- You can check out the SDK reference documentation for more details on the available functions and classes.
How would you rate this page?
Last updated on