Added in API level 31

UiTranslationStateCallback

interface UiTranslationStateCallback
android.view.translation.UiTranslationStateCallback

Callback for listening to UI Translation state changes. See android.view.translation.UiTranslationManager#registerUiTranslationStateCallback(java.util.concurrent.Executor,android.view.translation.UiTranslationStateCallback).

Prior to Android version android.os.Build.VERSION_CODES#TIRAMISU:

In Android version android.os.Build.VERSION_CODES#TIRAMISU and later:

Summary

Public methods
abstract Unit

The UI Translation session has ended.

open Unit
onFinished(packageName: String)

The UI Translation session has ended.

abstract Unit

The system is requesting that the application temporarily show the UI contents in their original language.

open Unit
onPaused(packageName: String)

The system is requesting that the application temporarily show the UI contents in their original language.

open Unit
onResumed(sourceLocale: ULocale, targetLocale: ULocale)

The system is requesting that the application restore from the temporarily paused state and show the content in the translated language.

open Unit
onResumed(sourceLocale: ULocale, targetLocale: ULocale, packageName: String)

The system is requesting that the application restore from the temporarily paused state and show the content in the translated language.

open Unit
onStarted(sourceLocale: ULocale, targetLocale: ULocale)

The system is requesting translation of the UI from sourceLocale to targetLocale.

open Unit
onStarted(sourceLocale: ULocale, targetLocale: ULocale, packageName: String)

The system is requesting translation of the UI from sourceLocale to targetLocale.

Public methods

onFinished

Added in API level 31
abstract fun onFinished(): Unit

The UI Translation session has ended.

Apps should implement onFinished(java.lang.String) as well if they need the name of the package that owns the activity being translated.

onFinished

Added in API level 33
open fun onFinished(packageName: String): Unit

The UI Translation session has ended.

Apps may implement onFinished() instead if they don't need the name of the package that owns the activity being translated.

Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU must implement onFinished() if they want to handle the "finished" event.

Parameters
packageName String: The name of the package that owns the activity being translated. This value cannot be null.

onPaused

Added in API level 31
abstract fun onPaused(): Unit

The system is requesting that the application temporarily show the UI contents in their original language.

Apps should implement onPaused(java.lang.String) as well if they need the name of the package that owns the activity being translated.

onPaused

Added in API level 33
open fun onPaused(packageName: String): Unit

The system is requesting that the application temporarily show the UI contents in their original language.

Apps may implement onPaused() instead if they don't need the name of the package that owns the activity being translated.

Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU must implement onPaused() if they want to handle the "paused" event.

Parameters
packageName String: This value cannot be null.

onResumed

Added in API level 31
open fun onResumed(
    sourceLocale: ULocale,
    targetLocale: ULocale
): Unit

The system is requesting that the application restore from the temporarily paused state and show the content in the translated language.

Apps should implement onResumed(android.icu.util.ULocale,android.icu.util.ULocale,java.lang.String) instead if they need the name of the package that owns the activity being translated.

Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU must implement this method if they want to handle the "resumed" event.

Parameters
sourceLocale ULocale: ULocale the UI is being translated from. This value cannot be null.
targetLocale ULocale: ULocale the UI is being translated to. This value cannot be null.

onResumed

Added in API level 33
open fun onResumed(
    sourceLocale: ULocale,
    targetLocale: ULocale,
    packageName: String
): Unit

The system is requesting that the application restore from the temporarily paused state and show the content in the translated language.

Apps may implement onResumed(android.icu.util.ULocale,android.icu.util.ULocale) instead if they don't need the name of the package that owns the activity being translated.

Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU must implement onResumed(android.icu.util.ULocale,android.icu.util.ULocale) if they want to handle the "resumed" event.

Parameters
sourceLocale ULocale: ULocale the UI is being translated from. This value cannot be null.
targetLocale ULocale: ULocale the UI is being translated to. This value cannot be null.
packageName String: The name of the package that owns the activity being translated. This value cannot be null.

onStarted

Added in API level 31
open fun onStarted(
    sourceLocale: ULocale,
    targetLocale: ULocale
): Unit

The system is requesting translation of the UI from sourceLocale to targetLocale.

This is also called if either the requested sourceLocale or targetLocale has changed.

Apps should implement onStarted(android.icu.util.ULocale,android.icu.util.ULocale,java.lang.String) instead if they need the name of the package that owns the activity being translated.

Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU must implement this method if they want to handle the "started" event.

Parameters
sourceLocale ULocale: ULocale the UI is being translated from. This value cannot be null.
targetLocale ULocale: ULocale the UI is being translated to. This value cannot be null.

onStarted

Added in API level 33
open fun onStarted(
    sourceLocale: ULocale,
    targetLocale: ULocale,
    packageName: String
): Unit

The system is requesting translation of the UI from sourceLocale to targetLocale.

This is also called if either the requested sourceLocale or targetLocale has changed.

Apps may implement onStarted(android.icu.util.ULocale,android.icu.util.ULocale) instead if they don't need the name of the package that owns the activity being translated.

Apps with minSdkVersion lower than android.os.Build.VERSION_CODES#TIRAMISU must implement onStarted(android.icu.util.ULocale,android.icu.util.ULocale) if they want to handle the "started" event.

Parameters
sourceLocale ULocale: ULocale the UI is being translated from. This value cannot be null.
targetLocale ULocale: ULocale the UI is being translated to. This value cannot be null.
packageName String: The name of the package that owns the activity being translated. This value cannot be null.