TranslationManager
class TranslationManager
| kotlin.Any | |
| ↳ | android.view.translation.TranslationManager | 
The TranslationManager class provides ways for apps to integrate and use the translation framework. 
The TranslationManager manages Translators and help bridge client calls to the server translation service 
Summary
| Public methods | |
|---|---|
| Unit | addOnDeviceTranslationCapabilityUpdateListener(executor: Executor, capabilityListener: Consumer<TranslationCapability!>)Adds a  | 
| Unit | createOnDeviceTranslator(translationContext: TranslationContext, executor: Executor, callback: Consumer<Translator!>)Creates an on-device Translator for natural language translation. | 
| MutableSet<TranslationCapability!> | getOnDeviceTranslationCapabilities(sourceFormat: Int, targetFormat: Int)Returns a set of  | 
| PendingIntent? | Returns an immutable PendingIntent which can be used to launch an activity to view/edit on-device translation settings. | 
| Unit | removeOnDeviceTranslationCapabilityUpdateListener(capabilityListener: Consumer<TranslationCapability!>)Removes a  | 
Public methods
addOnDeviceTranslationCapabilityUpdateListener
fun addOnDeviceTranslationCapabilityUpdateListener(
executor: Executor,
capabilityListener: Consumer<TranslationCapability!>
): Unit
Adds a TranslationCapability Consumer to listen for updates on states of on-device TranslationCapabilitys.
| Parameters | |
|---|---|
| capabilityListener | Consumer<TranslationCapability!>: a TranslationCapabilityConsumer to receive the updatedTranslationCapabilityfrom the on-device translation service. This value cannot benull. | 
| executor | Executor: This value cannot be null. Callback and listener events are dispatched through thisExecutor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can useContext.getMainExecutor(). Otherwise, provide anExecutorthat dispatches to an appropriate thread. | 
createOnDeviceTranslator
fun createOnDeviceTranslator(
translationContext: TranslationContext,
executor: Executor,
callback: Consumer<Translator!>
): Unit
Creates an on-device Translator for natural language translation.
In Android 12, this method provided the same cached Translator object when given the same TranslationContext object. Do not use a Translator destroyed elsewhere as this will cause an exception on Android 12.
In later versions, this method never returns a cached Translator.
| Parameters | |
|---|---|
| translationContext | TranslationContext: TranslationContextcontaining the specs for creating the Translator. This value cannot benull. | 
| executor | Executor: Executor to run callback operations This value cannot be null. Callback and listener events are dispatched through thisExecutor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can useContext.getMainExecutor(). Otherwise, provide anExecutorthat dispatches to an appropriate thread. | 
| callback | Consumer<Translator!>: Consumerto receive the translator. Anullvalue is returned if the service could not create the translator. | 
getOnDeviceTranslationCapabilities
fun getOnDeviceTranslationCapabilities(
sourceFormat: Int,
targetFormat: Int
): MutableSet<TranslationCapability!>
Returns a set of TranslationCapabilitys describing the capabilities for on-device Translators. 
These translation capabilities contains a source and target TranslationSpec representing the data expected for both ends of translation process. The capabilities provides the information and limitations for generating a TranslationContext. The context object can then be used by createOnDeviceTranslator(android.view.translation.TranslationContext,java.util.concurrent.Executor,java.util.function.Consumer) to obtain a Translator for translations.
NOTE: Call on a worker thread. 
 This method may take several seconds to complete, so it should only be called from a worker thread.
| Parameters | |
|---|---|
| sourceFormat | Int: data format for the input data to be translated. Value is android.view.translation.TranslationSpec#DATA_FORMAT_TEXT | 
| targetFormat | Int: data format for the expected translated output data. Value is android.view.translation.TranslationSpec#DATA_FORMAT_TEXT | 
| Return | |
|---|---|
| MutableSet<TranslationCapability!> | A set of TranslationCapabilitys. This value cannot benull. | 
getOnDeviceTranslationSettingsActivityIntent
fun getOnDeviceTranslationSettingsActivityIntent(): PendingIntent?
Returns an immutable PendingIntent which can be used to launch an activity to view/edit on-device translation settings.
| Return | |
|---|---|
| PendingIntent? | An immutable PendingIntent or nullif one of reason met:
 | 
removeOnDeviceTranslationCapabilityUpdateListener
fun removeOnDeviceTranslationCapabilityUpdateListener(capabilityListener: Consumer<TranslationCapability!>): Unit
Removes a TranslationCapability Consumer to listen for updates on states of on-device TranslationCapabilitys.
| Parameters | |
|---|---|
| capabilityListener | Consumer<TranslationCapability!>: the TranslationCapabilityConsumer to unregister This value cannot benull. | 
