Skip to content

Most visited

Recently visited

navigation
added in API level 26

TextClassifier

public interface TextClassifier

android.view.textclassifier.TextClassifier


Interface for providing text classification related features.

Unless otherwise stated, methods of this interface are blocking operations and you should avoid calling them on the UI thread.

Summary

Constants

String TYPE_ADDRESS

String TYPE_EMAIL

String TYPE_OTHER

String TYPE_PHONE

String TYPE_URL

Fields

public static final TextClassifier NO_OP

No-op TextClassifier.

Public methods

abstract TextClassification classifyText(CharSequence text, int startIndex, int endIndex, LocaleList defaultLocales)

Classifies the specified text and returns a TextClassification object that can be used to generate a widget for handling the classified text.

abstract TextSelection suggestSelection(CharSequence text, int selectionStartIndex, int selectionEndIndex, LocaleList defaultLocales)

Returns suggested text selection indices, recognized types and their associated confidence scores.

Constants

TYPE_ADDRESS

added in API level 26
String TYPE_ADDRESS

Constant Value: "address"

TYPE_EMAIL

added in API level 26
String TYPE_EMAIL

Constant Value: "email"

TYPE_OTHER

added in API level 26
String TYPE_OTHER

Constant Value: "other"

TYPE_PHONE

added in API level 26
String TYPE_PHONE

Constant Value: "phone"

TYPE_URL

added in API level 26
String TYPE_URL

Constant Value: "url"

Fields

NO_OP

added in API level 26
TextClassifier NO_OP

No-op TextClassifier. This may be used to turn off TextClassifier features.

Public methods

classifyText

added in API level 26
TextClassification classifyText (CharSequence text, 
                int startIndex, 
                int endIndex, 
                LocaleList defaultLocales)

Classifies the specified text and returns a TextClassification object that can be used to generate a widget for handling the classified text.

This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
text CharSequence: text providing context for the text to classify (which is specified by the sub sequence starting at startIndex and ending at endIndex)

This value must never be null.

startIndex int: start index of the text to classify

endIndex int: end index of the text to classify

defaultLocales LocaleList: ordered list of locale preferences that can be used to disambiguate the provided text. If no locale preferences exist, set this to null or an empty locale list in which case the classifier will decide whether to use no locale information, use a default locale, or use the system default.

Returns
TextClassification

This value will never be null.

Throws
IllegalArgumentException if text is null; startIndex is negative; endIndex is greater than text.length() or not greater than startIndex

suggestSelection

added in API level 26
TextSelection suggestSelection (CharSequence text, 
                int selectionStartIndex, 
                int selectionEndIndex, 
                LocaleList defaultLocales)

Returns suggested text selection indices, recognized types and their associated confidence scores. The selections are ordered from highest to lowest scoring.

This method may take several seconds to complete, so it should only be called from a worker thread.

Parameters
text CharSequence: text providing context for the selected text (which is specified by the sub sequence starting at selectionStartIndex and ending at selectionEndIndex)

This value must never be null.

selectionStartIndex int: start index of the selected part of text

selectionEndIndex int: end index of the selected part of text

defaultLocales LocaleList: ordered list of locale preferences that can be used to disambiguate the provided text. If no locale preferences exist, set this to null or an empty locale list in which case the classifier will decide whether to use no locale information, use a default locale, or use the system default.

Returns
TextSelection

This value will never be null.

Throws
IllegalArgumentException if text is null; selectionStartIndex is negative; selectionEndIndex is greater than text.length() or not greater than selectionStartIndex
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)