Android 8.1 introduces the TextClassfier API that uses machine learning techniques to help developers classify text:

TextClassificationManager tcm =
TextClassifier classifier = tcm.getTextClassifier();
TextSelection selection = classifier.suggestSelection(...);
TextClassification classification = classifier.classifyText(...);

Developers may choose to set a custom text classifier:


But if an app developer sets the text classifier to null, a system default text classifier is returned for getTextClassifier().

See: android.view.textclassifier.TextClassifierImpl

TextView and WebView use the TextClassifier for smart selection and smart text share features:

Figure 1. TEXTCLASSIFIER usage.

TextClassifier neural-net models

The Android Open Source Project (AOSP) features a number of neural network models for classifying text. Each model file is trained for a single language. You may choose to install any combination of models. The models are defined in:


Pre-installing language models on devices

You may specify a bundle of language models and install them on a device:

# -----------------------
# Smart Selection bundles
# -----------------------

include $(CLEAR_VARS)
LOCAL_MODULE           := textclassifier.smartselection.bundle1
LOCAL_REQUIRED_MODULES := textclassifier.smartselection.en.model

For example, in device/google/marlin/

# TextClassifier smart selection model files

Inspecting installed language modules

Use ADB to list the files in the directory:

$ adb shell ls -l /etc/textclassifier
-rw-r--r-- 1 root root ...
-rw-r--r-- 1 root root ... textclassifier.smartselection.en.model
-rw-r--r-- 1 root root ...
-rw-r--r-- 1 root root ...

Model updates

Models can be updated either by having a new model included as part of a system image update, or dynamically via having a system component that would trigger an update through the System API ACTION_UPDATE_SMART_SELECTION intent. By broadcasting this System API intent, the framework is able to update the language model of the currently set language. The models themselves contain the supported language and a version number so the latest appropriate model is used.

So you don't need to preload models for all languages because they can be added later. If no model file is found for the specified language, text classification will return no-op values.

Compatibility Test Suite tests

The associated Android Compatibility Test Suite (CTS) tests can be found in:



  • testSmartSelection
  • testSmartSelection_dragSelection
  • testSmartSelection_resetSelection