LocaleConfig


public class LocaleConfig
extends Object implements Parcelable

java.lang.Object
   ↳ android.app.LocaleConfig


The LocaleConfig of an application. There are two sources. One is from an XML resource file with an <locale-config> element and referenced in the manifest via android:localeConfig on <application>. The other is that the application dynamically provides an override version which is persisted in LocaleManager.setOverrideLocaleConfig(LocaleConfig).

For more information about the LocaleConfig from an XML resource file, see the section on per-app language preferences.

Summary

XML attributes

android:localeConfig An XML resource with the application's LocaleConfig

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name". 

android:name The IETF BCP47 language tag of the supported locale. 

Constants

int STATUS_NOT_SPECIFIED

No android:localeConfig tag on .

int STATUS_PARSING_FAILED

Malformed input in the XML file where the LocaleConfig was stored.

int STATUS_SUCCESS

succeeded reading the LocaleConfig structure stored in an XML file.

String TAG_LOCALE

String TAG_LOCALE_CONFIG

Inherited constants

Fields

public static final Creator<LocaleConfig> CREATOR

Public constructors

LocaleConfig(Context context)

Returns an override LocaleConfig if it has been set via LocaleManager.setOverrideLocaleConfig(LocaleConfig).

LocaleConfig(LocaleList locales)

Return the LocaleConfig with any sequence of locales combined into a LocaleList.

Public methods

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

static LocaleConfig fromContextIgnoringOverride(Context context)

Returns a LocaleConfig from the application resources regardless of whether any LocaleConfig is overridden via LocaleManager.setOverrideLocaleConfig(LocaleConfig).

Locale getDefaultLocale()

Returns the locale the strings in values/strings.xml (the default strings in the directory with no locale qualifier) are in if specified, otherwise null

int getStatus()

Get the status of reading the resource file where the LocaleConfig was stored.

LocaleList getSupportedLocales()

Returns the locales supported by the specified application.

void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Inherited methods

XML attributes

android:localeConfig

An XML resource with the application's LocaleConfig

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:name

The IETF BCP47 language tag of the supported locale. LocaleConfig

May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;

Constants

STATUS_NOT_SPECIFIED

Added in API level 33
public static final int STATUS_NOT_SPECIFIED

No android:localeConfig tag on .

Constant Value: 1 (0x00000001)

STATUS_PARSING_FAILED

Added in API level 33
public static final int STATUS_PARSING_FAILED

Malformed input in the XML file where the LocaleConfig was stored.

Constant Value: 2 (0x00000002)

STATUS_SUCCESS

Added in API level 33
public static final int STATUS_SUCCESS

succeeded reading the LocaleConfig structure stored in an XML file.

Constant Value: 0 (0x00000000)

TAG_LOCALE

Added in API level 33
public static final String TAG_LOCALE

Constant Value: "locale"

TAG_LOCALE_CONFIG

Added in API level 33
public static final String TAG_LOCALE_CONFIG

Constant Value: "locale-config"

Fields

CREATOR

Added in API level 34
public static final Creator<LocaleConfig> CREATOR

Public constructors

LocaleConfig

Added in API level 33
public LocaleConfig (Context context)

Returns an override LocaleConfig if it has been set via LocaleManager.setOverrideLocaleConfig(LocaleConfig). Otherwise, returns the LocaleConfig from the application resources.

Parameters
context Context: the context of the application. This value cannot be null.

LocaleConfig

Added in API level 34
public LocaleConfig (LocaleList locales)

Return the LocaleConfig with any sequence of locales combined into a LocaleList.

Note: Applications seeking to create an override LocaleConfig via LocaleManager.setOverrideLocaleConfig(LocaleConfig) should use this constructor to first create the LocaleConfig they intend the system to see as the override.

Note: The creation of this LocaleConfig does not automatically mean it will become the override config for an application. Any LocaleConfig desired to be the override must be passed into the LocaleManager.setOverrideLocaleConfig(LocaleConfig), otherwise it will not persist or affect the system's understanding of app-supported resources.

Parameters
locales LocaleList: the desired locales for a specified application This value cannot be null.

Public methods

describeContents

Added in API level 34
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 0 or CONTENTS_FILE_DESCRIPTOR

fromContextIgnoringOverride

Added in API level 34
public static LocaleConfig fromContextIgnoringOverride (Context context)

Returns a LocaleConfig from the application resources regardless of whether any LocaleConfig is overridden via LocaleManager.setOverrideLocaleConfig(LocaleConfig).

Parameters
context Context: the context of the application. This value cannot be null.

Returns
LocaleConfig This value cannot be null.

getDefaultLocale

Added in API level 35
public Locale getDefaultLocale ()

Returns the locale the strings in values/strings.xml (the default strings in the directory with no locale qualifier) are in if specified, otherwise null

Returns
Locale The default Locale or null

getStatus

Added in API level 33
public int getStatus ()

Get the status of reading the resource file where the LocaleConfig was stored.

Distinguish "the application didn't provide the resource file" from "the application provided malformed input" if getSupportedLocales() returns null.

Returns
int STATUS_SUCCESS if the LocaleConfig structure existed in an XML file was successfully read, or STATUS_NOT_SPECIFIED if no android:localeConfig tag on pointing to an XML file that stores the LocaleConfig, or STATUS_PARSING_FAILED if the application provided malformed input for the LocaleConfig structure. Value is STATUS_SUCCESS, STATUS_NOT_SPECIFIED, or STATUS_PARSING_FAILED

getSupportedLocales

Added in API level 33
public LocaleList getSupportedLocales ()

Returns the locales supported by the specified application.

Note: The locale format should follow the IETF BCP47 regular expression

Returns
LocaleList the LocaleList This value may be null.

writeToParcel

Added in API level 34
public void writeToParcel (Parcel dest, 
                int flags)

Flatten this object in to a Parcel.

Parameters
dest Parcel: This value cannot be null.

flags int: Additional flags about how the object should be written. May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES