TextClassification
  public
  
  final
  
  class
  TextClassification
  
    extends Object
  
  
  
  
  
      implements
      
        Parcelable
      
  
  
| java.lang.Object | |
| ↳ | android.view.textclassifier.TextClassification | 
Information for generating a widget to handle classified text.
A TextClassification object contains icons, labels, onClickListeners and intents that may be used to build a widget that can be used to act on classified text. There is the concept of a primary action and other secondary actions.
e.g. building a view that, when clicked, shares the classified text with the preferred app:
// Called preferably outside the UiThread.
   TextClassification classification = textClassifier.classifyText(allText, 10, 25);
   // Called on the UiThread.
   Button button = new Button(context);
   button.setCompoundDrawablesWithIntrinsicBounds(classification.getIcon(), null, null, null);
   button.setText(classification.getLabel());
   button.setOnClickListener(v -> classification.getActions().get(0).getActionIntent().send());
 e.g. starting an action mode with menu items that can handle the classified text:
// Called preferably outside the UiThread.
   final TextClassification classification = textClassifier.classifyText(allText, 10, 25);
   // Called on the UiThread.
   view.startActionMode(new ActionMode.Callback() {
       public boolean onCreateActionMode(ActionMode mode, Menu menu) {
           for (int i = 0; i < classification.getActions().size(); ++i) {
              RemoteAction action = classification.getActions().get(i);
              menu.add(Menu.NONE, i, 20, action.getTitle())
                 .setIcon(action.getIcon());
           }
           return true;
       }
       public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
           classification.getActions().get(item.getItemId()).getActionIntent().send();
           return true;
       }
       ...
   });
 Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        class | TextClassification.BuilderBuilder for building  | 
| 
        
        
        
        
        class | TextClassification.RequestA request object for generating TextClassification. | 
| Inherited constants | 
|---|
| Fields | |
|---|---|
| 
    public
    static
    final
    Creator<TextClassification> | CREATOR
 | 
| Public methods | |
|---|---|
| 
        
        
        
        
        
        int | 
      describeContents()
      Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. | 
| 
        
        
        
        
        
        List<RemoteAction> | 
      getActions()
      Returns a list of actions that may be performed on the text. | 
| 
        
        
        
        
        
        float | 
      getConfidenceScore(String entity)
      Returns the confidence score for the specified entity. | 
| 
        
        
        
        
        
        String | 
      getEntity(int index)
      Returns the entity at the specified index. | 
| 
        
        
        
        
        
        int | 
      getEntityCount()
      Returns the number of entities found in the classified text. | 
| 
        
        
        
        
        
        Bundle | 
      getExtras()
      Returns the extended data. | 
| 
        
        
        
        
        
        Drawable | 
      getIcon()
      
      This method was deprecated
      in API level 28.
    Use  | 
| 
        
        
        
        
        
        String | 
      getId()
      Returns the id, if one exists, for this object. | 
| 
        
        
        
        
        
        Intent | 
      getIntent()
      
      This method was deprecated
      in API level 28.
    Use  | 
| 
        
        
        
        
        
        CharSequence | 
      getLabel()
      
      This method was deprecated
      in API level 28.
    Use  | 
| 
        
        
        
        
        
        View.OnClickListener | 
      getOnClickListener()
      
      This method was deprecated
      in API level 28.
    Use  | 
| 
        
        
        
        
        
        String | 
      getText()
      Gets the classified text. | 
| 
        
        
        
        
        
        String | 
      toString()
      Returns a string representation of the object. | 
| 
        
        
        
        
        
        void | 
      writeToParcel(Parcel dest, int flags)
      Flatten this object in to a Parcel. | 
| Inherited methods | |
|---|---|
Fields
Public methods
describeContents
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable
 instance's marshaled representation. For example, if the object will
 include a file descriptor in the output of writeToParcel(android.os.Parcel, int),
 the return value of this method must include the
 CONTENTS_FILE_DESCRIPTOR bit.
| Returns | |
|---|---|
| int | a bitmask indicating the set of special object types marshaled
 by this Parcelable object instance.
 Value is either 0orCONTENTS_FILE_DESCRIPTOR | 
getActions
public List<RemoteAction> getActions ()
Returns a list of actions that may be performed on the text. The list is ordered based on the likelihood that a user will use the action, with the most likely action appearing first.
| Returns | |
|---|---|
| List<RemoteAction> | |
getConfidenceScore
public float getConfidenceScore (String entity)
Returns the confidence score for the specified entity. The value ranges from 0 (low confidence) to 1 (high confidence). 0 indicates that the entity was not found for the classified text.
| Parameters | |
|---|---|
| entity | String: Value isTextClassifier.TYPE_UNKNOWN,TextClassifier.TYPE_OTHER,TextClassifier.TYPE_EMAIL,TextClassifier.TYPE_PHONE,TextClassifier.TYPE_ADDRESS,TextClassifier.TYPE_URL,TextClassifier.TYPE_DATE,TextClassifier.TYPE_DATE_TIME,TextClassifier.TYPE_FLIGHT_NUMBER, android.view.textclassifier.TextClassifier.TYPE_DICTIONARY,TextClassifier.TYPE_OTP, orTextClassifier.TYPE_SMS_RETRIEVER_OTP | 
| Returns | |
|---|---|
| float | Value is between 0.0f and 1.0f inclusive | 
getEntity
public String getEntity (int index)
Returns the entity at the specified index. Entities are ordered from high confidence to low confidence.
| Parameters | |
|---|---|
| index | int | 
| Returns | |
|---|---|
| String | This value cannot be null.
 Value isTextClassifier.TYPE_UNKNOWN,TextClassifier.TYPE_OTHER,TextClassifier.TYPE_EMAIL,TextClassifier.TYPE_PHONE,TextClassifier.TYPE_ADDRESS,TextClassifier.TYPE_URL,TextClassifier.TYPE_DATE,TextClassifier.TYPE_DATE_TIME,TextClassifier.TYPE_FLIGHT_NUMBER, android.view.textclassifier.TextClassifier.TYPE_DICTIONARY,TextClassifier.TYPE_OTP, orTextClassifier.TYPE_SMS_RETRIEVER_OTP | 
| Throws | |
|---|---|
| IndexOutOfBoundsException | if the specified index is out of range. | 
See also:
getEntityCount
public int getEntityCount ()
Returns the number of entities found in the classified text.
| Returns | |
|---|---|
| int | Value is 0 or greater | 
getExtras
public Bundle getExtras ()
Returns the extended data.
NOTE: Do not modify this bundle.
| Returns | |
|---|---|
| Bundle | This value cannot be null. | 
getIcon
public Drawable getIcon ()
      This method was deprecated
      in API level 28.
    Use getActions() instead.
  
Returns an icon that may be rendered on a widget used to act on the classified text.
NOTE: This field is not parcelable and only represents the icon of the
 first RemoteAction (if one exists) when this object is read from a parcel.
| Returns | |
|---|---|
| Drawable | This value may be null. | 
getId
public String getId ()
Returns the id, if one exists, for this object.
| Returns | |
|---|---|
| String | This value may be null. | 
getIntent
public Intent getIntent ()
      This method was deprecated
      in API level 28.
    Use getActions() instead.
  
Returns an intent that may be fired to act on the classified text.
NOTE: This field is not parcelled and will always return null when this object is read from a parcel.
| Returns | |
|---|---|
| Intent | |
getLabel
public CharSequence getLabel ()
      This method was deprecated
      in API level 28.
    Use getActions() instead.
  
Returns a label that may be rendered on a widget used to act on the classified text.
NOTE: This field is not parcelable and only represents the label of the
 first RemoteAction (if one exists) when this object is read from a parcel.
| Returns | |
|---|---|
| CharSequence | This value may be null. | 
getOnClickListener
public View.OnClickListener getOnClickListener ()
      This method was deprecated
      in API level 28.
    Use getActions() instead.
  
Returns the OnClickListener that may be triggered to act on the classified text.
NOTE: This field is not parcelable and only represents the first
 RemoteAction (if one exists) when this object is read from a parcel.
| Returns | |
|---|---|
| View.OnClickListener | This value may be null. | 
getText
public String getText ()
Gets the classified text.
| Returns | |
|---|---|
| String | This value may be null. | 
toString
public String toString ()
Returns a string representation of the object.
| Returns | |
|---|---|
| String | a string representation of the object. | 
writeToParcel
public void writeToParcel (Parcel dest, int flags)
Flatten this object in to a Parcel.
| Parameters | |
|---|---|
| dest | Parcel: The Parcel in which the object should be written.
 This value cannot benull. | 
| flags | int: Additional flags about how the object should be written.
 May be 0 orParcelable.PARCELABLE_WRITE_RETURN_VALUE.
 Value is either0or a combination ofParcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES | 
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
