# CredentialOption.Builder

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Builder

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/credentials/CredentialOption.Builder "View this page in Java")  

```
class Builder
```

|---|----------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                               ||
| ↳ | [android.credentials.CredentialOption.Builder](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#) |

A builder for[CredentialOption](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption).

## Summary

|                                                                                                                                                                                                                                           Public constructors                                                                                                                                                                                                                                            ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#Builder(kotlin.String,%20android.os.Bundle,%20android.os.Bundle))`(`type:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `credentialRetrievalData:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)`, `candidateQueryData:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)`)` <br /> |

|                                                                                                                                                                                                                                                                                                                                                                  Public methods                                                                                                                                                                                                                                                                                                                                                                  ||
|--------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [CredentialOption.Builder](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#) | [addAllowedProvider](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#addAllowedProvider(android.content.ComponentName))`(`allowedProvider:` `[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)`)` Adds a provider[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)to be queried while gathering credentials from credential providers on the device.                                                                                                                   |
| [CredentialOption](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption)                  | [build](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#build())`()` Builds a[CredentialOption](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption).                                                                                                                                                                                                                                                                                                                                                                                      |
| [CredentialOption.Builder](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#) | [setAllowedProviders](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#setAllowedProviders(kotlin.collections.MutableSet))`(`allowedProviders:` `[MutableSet](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-set/index.html)<[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)!>`)` Sets a set of provider[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)to be queried while gathering credentials from credential providers on the device. |
| [CredentialOption.Builder](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#) | [setIsSystemProviderRequired](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#setIsSystemProviderRequired(kotlin.Boolean))`(`isSystemProviderRequired:` `[Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)`)` Sets a true/false value corresponding to whether this option must be serviced by system credentials providers only.                                                                                                                                                                                                         |

## Public constructors

### Builder

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Builder(
    type: String, 
    credentialRetrievalData: Bundle, 
    candidateQueryData: Bundle)
```

|                                                                                                                       Parameters                                                                                                                        ||
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `type`                    | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):the type of the credential option This value cannot be`null`.                                                                               |
| `credentialRetrievalData` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):the full request data This value cannot be`null`.                                                                                           |
| `candidateQueryData`      | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#):the partial request data that will be sent to the provider during the initial credential candidate query stage. This value cannot be`null`. |

|                                            Exceptions                                            ||
|--------------------------------------|------------------------------------------------------------|
| `java.lang.IllegalArgumentException` | If`type`is null, or empty                                  |
| `java.lang.NullPointerException`     | If`credentialRetrievalData`, or`candidateQueryData`is null |

## Public methods

### addAllowedProvider

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun addAllowedProvider(allowedProvider: ComponentName): CredentialOption.Builder
```

Adds a provider[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)to be queried while gathering credentials from credential providers on the device. If no candidate providers are specified, all user configured and system credential providers will be queried in the candidate query phase. If an invalid component name is provided, or a service corresponding to the component name does not exist on the device, that component name is ignored. If all component names are invalid, or not present on the device, no providers are queried and no credentials are retrieved.

|                                                                     Parameters                                                                     ||
|-------------------|---------------------------------------------------------------------------------------------------------------------------------|
| `allowedProvider` | [ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#):This value cannot be`null`. |

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [CredentialOption.Builder](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#) | This value cannot be`null`. |

|                          Exceptions                          ||
|----------------------------------|----------------------------|
| `java.lang.NullPointerException` | If`allowedProvider`is null |

### build

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun build(): CredentialOption
```

Builds a[CredentialOption](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption).

|                                                                Return                                                                ||
|---------------------------------------------------------------------------------------------------------|-----------------------------|
| [CredentialOption](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption) | This value cannot be`null`. |

### setAllowedProviders

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setAllowedProviders(allowedProviders: MutableSet<ComponentName!>): CredentialOption.Builder
```

Sets a set of provider[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)to be queried while gathering credentials from credential providers on the device. If no candidate providers are specified, all user configured and system credential providers will be queried in the candidate query phase. If an invalid component name is provided, or a service corresponding to the component name does not exist on the device, that component name is ignored. If all component names are invalid, or not present on the device, no providers are queried and no credentials are retrieved.

|                                                                                                                          Parameters                                                                                                                           ||
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `allowedProviders` | [MutableSet](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-set/index.html)\<[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)!\>:This value cannot be`null`. |

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [CredentialOption.Builder](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#) | This value cannot be`null`. |

|                                           Exceptions                                            ||
|----------------------------------|---------------------------------------------------------------|
| `java.lang.NullPointerException` | If`allowedProviders`is null, or any of its elements are null. |

### setIsSystemProviderRequired

Added in[API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun setIsSystemProviderRequired(isSystemProviderRequired: Boolean): CredentialOption.Builder
```

Sets a true/false value corresponding to whether this option must be serviced by system credentials providers only.

|                                                                        Return                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [CredentialOption.Builder](https://developer.android.com/reference/kotlin/android/credentials/CredentialOption.Builder#) | This value cannot be`null`. |