Emoji are Unicode characters. Based on the Unicode character table, Emoji flags consist of 26 Unicode (AZ) alphabetic characters for encoding ISO 3166-1 alpha-2 two-letter codes ( wiki ).
This means that you can split the two-letter country code and convert each letter AZ to the regional letter of the indicator symbol:
private String localeToEmoji(Locale locale) { String countryCode = locale.getCountry(); int firstLetter = Character.codePointAt(countryCode, 0) - 0x41 + 0x1F1E6; int secondLetter = Character.codePointAt(countryCode, 1) - 0x41 + 0x1F1E6; return new String(Character.toChars(firstLetter)) + new String(Character.toChars(secondLetter)); }
Where 0x41 is the uppercase letter A , and 0x1F1E6 is the REGIONAL INDICATOR SYMBOL LETTER A in the Unicode table.
Note. This sample code is simplified and does not require country code checks that may not be available within the locale.
Dmitry
source share