To present an mDL over BLE, you will need to use the following components:
The CredentialViewModel Component
The IsoMdlPresentation Component
During the presentation, you will have to manage the PresentmentState. The PresentmentState definition is repeated here to show the stages that the presentation goes through. The View that manages your UI should deal with each one of these listed cases. Again, we have an example to give you some inspiration.
// The different Wallet-side states of an mDL presentation.
enum class PresentmentState {
/// Presentment has yet to start
UNINITIALIZED,
/// App should display the error message
ERROR,
/// App should display the QR code
ENGAGING_QR_CODE,
/// App should display an interactive page for the user to chose which values to reveal
SELECT_NAMESPACES,
/// App should display a success message and offer to close the page
SUCCESS,
}
1. Define your Mdl Sharing View
@Composable
fun MdlShareView(
credentialViewModel: CredentialsViewModel,
) {
val context = LocalContext.current
val session by credentialViewModel.session.collectAsState()
val currentState by credentialViewModel.currState.collectAsState()
when (currentState) {
// Implement your UI based on the PresentmentState
}
}
2. Implement the Engaging_Qr_Code status
// Instantiate the CredentialViewModel
val credentialViewModel = ViewModelProvider.AndroidViewModelFactory(application)
.create(CredentialsViewModel::class.java)
val session = credentialViewModel.session.collectAsState()
// Generate a QR code uri to embed.
let uri = session.getQrCodeUri()
// Then, generate the QR image
3. Implement the Submit_Namespaces status
In the step, the user needs to permit datafields to be shared. The Showcase app achieves this with the MdocFieldSelector.
// The submitNamespaces() method can be called from the credentialViewModel
// To set the allowedNamespaces value in the credentialViewModel, implement a UI that
// allows a user to select which data fields can be shared.
val allowedNamespaces by credentialViewModel.allowedNamespaces.collectAsState()
credentialViewmodel.submitNamespace(allowedNamespaces)
4. Implement the other PresentmentStates
The remaining PresentmentStates are available for you to implement the rest of the user experience.