Unicode and internationalization support

Android leverages the
ICU
library and
CLDR project to provide Unicode and other internationalization
support. This document's discussion of Unicode and internationalization support is divided into two
sections: Android 6.0 (API level 23) and lower, and Android 7.0 (API level 24) and higher.

Unicode and internationalization support through Android 6.0 (API level 23)

The Android platform uses ICU and CLDR to implement various
classes for handling both Latin and non-Latin orthographies, exposing classes
like Locale, Character, and many subclasses of
java.text. An app that internationalization functionalities beyond
the exposed classes, and targets versions of the platform through Android 6.0
(API level 23), must include the ICU library in its APK.

Apps targeting Android 7.0 (API level 24) or higher can leverage more comprehensive
support for Unicode and internationalization that is exposed by the Android framework.
The next section of this document provides details about that support.

Unicode and internationalization support in Android 7.0 (API level 24) and higher

Starting from Android 7.0 (API level 24), the Android platform
exposes a subset of the ICU4J APIs for app developers
to use under the android.icu package.
ICU4J is an open-source, widely used set of Java libraries providing Unicode
and internationalization support for software applications.

The ICU4J APIs use
localization data present on the device. As a result, you can reduce your APK
footprint by not compiling the ICU4J libraries into your APK; instead, you can
simply call out to them in the framework. (In this case, you may want to provide
multiple versions
of your APK, so users running versions of Android lower than
Android 7.0 (API level 24)
can download a version of the app that contains the ICU4J libraries.)

This document begins by providing some basic information on the minimum
Android API levels required to support these libraries. It then explains what
you need to know about the Android-specific implementation of ICU4J. Finally,
it tells you how to use the ICU4J APIs in the Android framework.

ICU4J on Android

Android exposes a subset of the ICU4J APIs via the
android.icu package, rather than com.ibm.icu. The
Android framework may choose not to
expose ICU4J APIs for various reasons: for example, because APIs are deprecated
or not declared stable. As the ICU team deprecates APIs in the future,
Android will also mark them as deprecated but will continue to include them.

In some cases, the Android framework supports more characters than do
the ICU libraries. This is true, for example, of the android.text class's
support for emoji.

Migrating to the android.icu package from com.ibm.icu

If you are already using the ICU4J APIs in your app, and the
android.icu APIs meet your requirements, then migrating to
the framework APIs requires you to change your Java imports
from com.ibm.icu to android.icu. You may then
remove your own copy of ICU4J files from the APK.

Note: The ICU4J framework APIs use the android.icu
namespace instead of com.ibm.icu. This is to avoid namespace
conflicts in APKs that contain their own com.ibm.icu libraries.

Migrating to android.icu APIs from other Android SDK APIs

Some classes in the java andandroid packages have
equivalents to those found in ICU4J. However, ICU4J often provides broader
support for standards and languages.

Table 2 shows some examples of these equivalencies to get you started:

24h/12h Time format setting

ICU on Android does not observe the user's 24h/12h time format setting (obtained from
DateFormat.is24HourFormat()).
In order to observe the setting, either use
DateFormat or
DateUtils
time formatting methods or use ICU time formatting patterns with appropriate hour pattern
symbols ('h' for 12h, 'H' for 24h) for different is24HourFormat() return values.
For example, this code will generate a string with current time that observes the user's 12h/24h setting: