# DigitalCredential

Artifact: [androidx.credentials:credentials](https://developer.android.com/jetpack/androidx/releases/credentials) [View Source](https://cs.android.com/search?q=file:androidx/credentials/DigitalCredential.kt+class:androidx.credentials.DigitalCredential) Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.5.0)

*** ** * ** ***

<br />

```
@ExperimentalDigitalCredentialApi
public final class DigitalCredential extends Credential
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.credentials.Credential](https://developer.android.com/reference/androidx/credentials/Credential) ||
|   | ↳ | [androidx.credentials.DigitalCredential](https://developer.android.com/reference/androidx/credentials/DigitalCredential) |

*** ** * ** ***

Represents the user's digital credential, generally used for verification or sign-in purposes.

Notice, this class does not necessarily always represents a successful digital credential. Depending on the protocol in your request, the `https://developer.android.com/reference/androidx/credentials/DigitalCredential#credentialJson()` may contain a failure response generated from the provider. Therefore, please follow the protocol specification to parse the `https://developer.android.com/reference/androidx/credentials/DigitalCredential#credentialJson()` and determine the failure / success response. For example, [here](https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-error-response) is the error response definition for the OpenID for Verifiable Presentations protocol.

When you make an OpenID4VP request for multiple credentials, you may receive a `https://developer.android.com/reference/androidx/credentials/GetCredentialResponse` containing a list of `https://developer.android.com/reference/androidx/credentials/DigitalCredential`. These credentials may be aggregated from one or more providers. Because some responses may contain an OpenID4VP error, you should check each individual `https://developer.android.com/reference/androidx/credentials/DigitalCredential` to ensure it satisfies your overall request.

NOTE: For non-protocol errors (system-level infrastructure failures, provider crashes, or generic CredMan exceptions), the transaction will NOT return any partial credentials at all. Such failures trigger an immediate transaction abort where zero credentials are yielded.

## Summary

| ### Constants |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/credentials/DigitalCredential#TYPE_DIGITAL_CREDENTIAL()` The type value for public key credential related operations. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/credentials/DigitalCredential#DigitalCredential(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html credentialJson)` Constructs a `DigitalCredential`. |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/credentials/DigitalCredential#getCredentialJson()()` the digital credential in the JSON format; the latest format is defined at https://wicg.github.io/digital-credentials/#the-digitalcredential-interface |

### Inherited methods

From [androidx.credentials.Credential](https://developer.android.com/reference/androidx/credentials/Credential) `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/androidx/credentials/Credential#getData()()`

the credential data in the `https://developer.android.com/reference/android/os/Bundle.html` format
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/androidx/credentials/Credential#getType()()`

the credential type determined by the credential-type-specific subclass (e.g. `https://developer.android.com/reference/androidx/credentials/PasswordCredential#TYPE_PASSWORD_CREDENTIAL()` for `PasswordCredential` or `https://developer.android.com/reference/androidx/credentials/PublicKeyCredential#TYPE_PUBLIC_KEY_CREDENTIAL()` for `PublicKeyCredential`)

## Constants

### TYPE_DIGITAL_CREDENTIAL

```
public static final @NonNull String TYPE_DIGITAL_CREDENTIAL
```

The type value for public key credential related operations.

## Public constructors

### DigitalCredential

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.5.0)

```
public DigitalCredential(@NonNull String credentialJson)
```

Constructs a `DigitalCredential`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html credentialJson` | the digital credential in the JSON format; the latest format is defined at https://wicg.github.io/digital-credentials/#the-digitalcredential-interface |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the `credentialJson` is not a valid json |

## Public methods

### getCredentialJson

Added in [1.5.0](https://developer.android.com/jetpack/androidx/releases/credentials#1.5.0)

```
public final @NonNull String getCredentialJson()
```

the digital credential in the JSON format; the latest format is defined at https://wicg.github.io/digital-credentials/#the-digitalcredential-interface