# TextClassification.Builder

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

# Builder

*** ** * ** ***

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

```
class Builder
```

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

Builder for building[TextClassification](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification)objects.

e.g.  

```kotlin
<code>TextClassification classification = new TextClassification.Builder()
           .setText(classifiedText)
           .setEntityType(TextClassifier.TYPE_EMAIL, 0.9)
           .setEntityType(TextClassifier.TYPE_OTHER, 0.1)
           .addAction(remoteAction1)
           .addAction(remoteAction2)
           .build();
  </code>
```

## Summary

|                                                           Public constructors                                                            ||
|---------------------------------------------------------------------------------------------------------------------------------------|---|
| [Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#Builder())`()` <br /> |

|                                                                                                                                                                                                                                                                                         Public methods                                                                                                                                                                                                                                                                                         ||
|--------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [addAction](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#addAction(android.app.RemoteAction))`(`action:` `[RemoteAction](https://developer.android.com/reference/kotlin/android/app/RemoteAction.html#)`)` Adds an action that may be performed on the classified text.                                                                                                                         |
| [TextClassification](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification)                  | [build](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#build())`()` Builds and returns a[TextClassification](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification)object.                                                                                                                                                                                |
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [setEntityType](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#setEntityType(kotlin.String,%20kotlin.Float))`(`type:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `confidenceScore:` `[Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html)`)` Sets an entity type for the classification result and assigns a confidence score. |
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [setExtras](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#setExtras(android.os.Bundle))`(`extras:` `[Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?`)` Sets the extended data.                                                                                                                                                                                 |
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [setIcon](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#setIcon(android.graphics.drawable.Drawable))`(`icon:` `[Drawable](https://developer.android.com/reference/kotlin/android/graphics/drawable/Drawable.html#)?`)` Sets the icon for the*primary*action that may be rendered on a widget used to act on the classified text.                                                                 |
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [setId](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#setId(kotlin.String))`(`id:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` Sets an id for the TextClassification object.                                                                                                                                                                           |
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [setIntent](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#setIntent(android.content.Intent))`(`intent:` `[Intent](https://developer.android.com/reference/kotlin/android/content/Intent.html#)?`)` Sets the intent for the*primary*action that may be fired to act on the classified text.                                                                                                       |
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [setLabel](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#setLabel(kotlin.String))`(`label:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` Sets the label for the*primary*action that may be rendered on a widget used to act on the classified text.                                                                                                     |
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [setOnClickListener](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#setOnClickListener(android.view.View.OnClickListener))`(`onClickListener:` `[View.OnClickListener](https://developer.android.com/reference/kotlin/android/view/View.OnClickListener.html#)?`)` Sets the OnClickListener for the*primary*action that may be triggered to act on the classified text.                           |
| [TextClassification.Builder](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#) | [setText](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#setText(kotlin.String))`(`text:` `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?`)` Sets the classified text.                                                                                                                                                                                         |

## Public constructors

### Builder

```
Builder()
```

## Public methods

### addAction

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

```
fun addAction(action: RemoteAction): TextClassification.Builder
```

Adds an action that may be performed on the classified text. Actions should be added in order of likelihood that the user will use them, with the most likely action being added first.

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

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

### build

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

```
fun build(): TextClassification
```

Builds and returns a[TextClassification](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification)object.

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

### setEntityType

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

```
fun setEntityType(
    type: String, 
    confidenceScore: Float
): TextClassification.Builder
```

Sets an entity type for the classification result and assigns a confidence score. If a confidence score had already been set for the specified entity type, this will override that score.

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        ||
|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `confidenceScore` | [Float](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-float/index.html):a value from 0 (low confidence) to 1 (high confidence). 0 implies the entity does not exist for the classified text. Values greater than 1 are clamped to 1. Value is between 0.0f and 1.0f inclusive                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `type`            | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html):This value cannot be`null`. Value is[android.view.textclassifier.TextClassifier#TYPE_UNKNOWN](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_UNKNOWN:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_OTHER](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_OTHER:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_EMAIL](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_EMAIL:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_PHONE](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_PHONE:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_ADDRESS](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_ADDRESS:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_URL](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_URL:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_DATE](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_DATE:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_DATE_TIME](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_DATE_TIME:kotlin.String),[android.view.textclassifier.TextClassifier#TYPE_FLIGHT_NUMBER](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_FLIGHT_NUMBER:kotlin.String), android.view.textclassifier.TextClassifier.TYPE_DICTIONARY,[android.view.textclassifier.TextClassifier#TYPE_OTP](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_OTP:kotlin.String), or[android.view.textclassifier.TextClassifier#TYPE_SMS_RETRIEVER_OTP](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassifier#TYPE_SMS_RETRIEVER_OTP:kotlin.String) |

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

### setExtras

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

```
fun setExtras(extras: Bundle?): TextClassification.Builder
```

Sets the extended data.

|                                                      Parameters                                                      ||
|----------|------------------------------------------------------------------------------------------------------------|
| `extras` | [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)?:This value may be`null`. |

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

### setIcon

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

```
fun setIcon(icon: Drawable?): TextClassification.Builder
```

**Deprecated:** *Use[addAction(android.app.RemoteAction)](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#addAction(android.app.RemoteAction))instead.*

Sets the icon for the*primary*action that may be rendered on a widget used to act on the classified text.

**NOTE:** This field is not parcelled. If read from a parcel, the returned icon represents the icon of the first[RemoteAction](https://developer.android.com/reference/kotlin/android/app/RemoteAction.html#)(if one exists).

|                                                              Parameters                                                               ||
|--------|-------------------------------------------------------------------------------------------------------------------------------|
| `icon` | [Drawable](https://developer.android.com/reference/kotlin/android/graphics/drawable/Drawable.html#)?:This value may be`null`. |

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

### setId

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

```
fun setId(id: String?): TextClassification.Builder
```

Sets an id for the TextClassification object.

|                                                    Parameters                                                    ||
|------|------------------------------------------------------------------------------------------------------------|
| `id` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:This value may be`null`. |

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

### setIntent

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

```
fun setIntent(intent: Intent?): TextClassification.Builder
```

**Deprecated:** *Use[addAction(android.app.RemoteAction)](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#addAction(android.app.RemoteAction))instead.*

Sets the intent for the*primary*action that may be fired to act on the classified text.

**NOTE:**This field is not parcelled.

|                                                        Parameters                                                         ||
|----------|-----------------------------------------------------------------------------------------------------------------|
| `intent` | [Intent](https://developer.android.com/reference/kotlin/android/content/Intent.html#)?:This value may be`null`. |

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

### setLabel

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

```
fun setLabel(label: String?): TextClassification.Builder
```

**Deprecated:** *Use[addAction(android.app.RemoteAction)](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#addAction(android.app.RemoteAction))instead.*

Sets the label for the*primary*action that may be rendered on a widget used to act on the classified text.

**NOTE:** This field is not parcelled. If read from a parcel, the returned label represents the label of the first[RemoteAction](https://developer.android.com/reference/kotlin/android/app/RemoteAction.html#)(if one exists).

|                                                     Parameters                                                      ||
|---------|------------------------------------------------------------------------------------------------------------|
| `label` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:This value may be`null`. |

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

### setOnClickListener

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

```
fun setOnClickListener(onClickListener: View.OnClickListener?): TextClassification.Builder
```

**Deprecated:** *Use[addAction(android.app.RemoteAction)](https://developer.android.com/reference/kotlin/android/view/textclassifier/TextClassification.Builder#addAction(android.app.RemoteAction))instead.*

Sets the OnClickListener for the*primary*action that may be triggered to act on the classified text.

**NOTE:** This field is not parcelable. If read from a parcel, the returned OnClickListener represents the first[RemoteAction](https://developer.android.com/reference/kotlin/android/app/RemoteAction.html#)(if one exists).

|                                                                         Parameters                                                                          ||
|-------------------|------------------------------------------------------------------------------------------------------------------------------------------|
| `onClickListener` | [View.OnClickListener](https://developer.android.com/reference/kotlin/android/view/View.OnClickListener.html#)?:This value may be`null`. |

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

### setText

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

```
fun setText(text: String?): TextClassification.Builder
```

Sets the classified text.

|                                                     Parameters                                                     ||
|--------|------------------------------------------------------------------------------------------------------------|
| `text` | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?:This value may be`null`. |

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