Home ยป Android ยป java – Get emoji flag by country code

java – Get emoji flag by country code

Posted by: admin June 15, 2020 Leave a comment

Questions:

There is a list of countries codes, I need to attach emoji flag to each one.
Is there a way to extract unicode from it or find emoji for country code?

This npm example looks similar for my goal (but uses hexadecimal as input) https://github.com/thekelvinliu/country-code-emoji/blob/master/src/index.js

How to&Answers:

This code snippet worked for me. Just replace "US" with whichever valid country code (based on the Regional Indicator Symbol Letยญters) you like and it will create a String flag containing the flag emoji for that country. (Reference)

int flagOffset = 0x1F1E6;
int asciiOffset = 0x41;

String country = "US";

int firstChar = Character.codePointAt(country, 0) - asciiOffset + flagOffset;
int secondChar = Character.codePointAt(country, 1) - asciiOffset + flagOffset;

String flag = new String(Character.toChars(firstChar))
            + new String(Character.toChars(secondChar));

This answer helped

Answer๏ผš

function getFlags($code){ $code = strtoupper($code); if($code == 'AD') return '๐Ÿ‡ฆ๐Ÿ‡ฉ'; if($code == 'AE') return '๐Ÿ‡ฆ๐Ÿ‡ช'; if($code == 'AF') return '๐Ÿ‡ฆ๐Ÿ‡ซ'; if($code == 'AG') return '๐Ÿ‡ฆ๐Ÿ‡ฌ'; if($code == 'AI') return '๐Ÿ‡ฆ๐Ÿ‡ฎ'; if($code == 'AL') return '๐Ÿ‡ฆ๐Ÿ‡ฑ'; if($code == 'AM') return '๐Ÿ‡ฆ๐Ÿ‡ฒ'; if($code == 'AO') return '๐Ÿ‡ฆ๐Ÿ‡ด'; if($code == 'AQ') return '๐Ÿ‡ฆ๐Ÿ‡ถ'; if($code == 'AR') return '๐Ÿ‡ฆ๐Ÿ‡ท'; if($code == 'AS') return '๐Ÿ‡ฆ๐Ÿ‡ธ'; if($code == 'AT') return '๐Ÿ‡ฆ๐Ÿ‡น'; if($code == 'AU') return '๐Ÿ‡ฆ๐Ÿ‡บ'; if($code == 'AW') return '๐Ÿ‡ฆ๐Ÿ‡ผ'; if($code == 'AX') return '๐Ÿ‡ฆ๐Ÿ‡ฝ'; if($code == 'AZ') return '๐Ÿ‡ฆ๐Ÿ‡ฟ'; if($code == 'BA') return '๐Ÿ‡ง๐Ÿ‡ฆ'; if($code == 'BB') return '๐Ÿ‡ง๐Ÿ‡ง'; if($code == 'BD') return '๐Ÿ‡ง๐Ÿ‡ฉ'; if($code == 'BE') return '๐Ÿ‡ง๐Ÿ‡ช'; if($code == 'BF') return '๐Ÿ‡ง๐Ÿ‡ซ'; if($code == 'BG') return '๐Ÿ‡ง๐Ÿ‡ฌ'; if($code == 'BH') return '๐Ÿ‡ง๐Ÿ‡ญ'; if($code == 'BI') return '๐Ÿ‡ง๐Ÿ‡ฎ'; if($code == 'BJ') return '๐Ÿ‡ง๐Ÿ‡ฏ'; if($code == 'BL') return '๐Ÿ‡ง๐Ÿ‡ฑ'; if($code == 'BM') return '๐Ÿ‡ง๐Ÿ‡ฒ'; if($code == 'BN') return '๐Ÿ‡ง๐Ÿ‡ณ'; if($code == 'BO') return '๐Ÿ‡ง๐Ÿ‡ด'; if($code == 'BQ') return '๐Ÿ‡ง๐Ÿ‡ถ'; if($code == 'BR') return '๐Ÿ‡ง๐Ÿ‡ท'; if($code == 'BS') return '๐Ÿ‡ง๐Ÿ‡ธ'; if($code == 'BT') return '๐Ÿ‡ง๐Ÿ‡น'; if($code == 'BV') return '๐Ÿ‡ง๐Ÿ‡ป'; if($code == 'BW') return '๐Ÿ‡ง๐Ÿ‡ผ'; if($code == 'BY') return '๐Ÿ‡ง๐Ÿ‡พ'; if($code == 'BZ') return '๐Ÿ‡ง๐Ÿ‡ฟ'; if($code == 'CA') return '๐Ÿ‡จ๐Ÿ‡ฆ'; if($code == 'CC') return '๐Ÿ‡จ๐Ÿ‡จ'; if($code == 'CD') return '๐Ÿ‡จ๐Ÿ‡ฉ'; if($code == 'CF') return '๐Ÿ‡จ๐Ÿ‡ซ'; if($code == 'CG') return '๐Ÿ‡จ๐Ÿ‡ฌ'; if($code == 'CH') return '๐Ÿ‡จ๐Ÿ‡ญ'; if($code == 'CI') return '๐Ÿ‡จ๐Ÿ‡ฎ'; if($code == 'CK') return '๐Ÿ‡จ๐Ÿ‡ฐ'; if($code == 'CL') return '๐Ÿ‡จ๐Ÿ‡ฑ'; if($code == 'CM') return '๐Ÿ‡จ๐Ÿ‡ฒ'; if($code == 'CN') return '๐Ÿ‡จ๐Ÿ‡ณ'; if($code == 'CO') return '๐Ÿ‡จ๐Ÿ‡ด'; if($code == 'CR') return '๐Ÿ‡จ๐Ÿ‡ท'; if($code == 'CU') return '๐Ÿ‡จ๐Ÿ‡บ'; if($code == 'CV') return '๐Ÿ‡จ๐Ÿ‡ป'; if($code == 'CW') return '๐Ÿ‡จ๐Ÿ‡ผ'; if($code == 'CX') return '๐Ÿ‡จ๐Ÿ‡ฝ'; if($code == 'CY') return '๐Ÿ‡จ๐Ÿ‡พ'; if($code == 'CZ') return '๐Ÿ‡จ๐Ÿ‡ฟ'; if($code == 'DE') return '๐Ÿ‡ฉ๐Ÿ‡ช'; if($code == 'DJ') return '๐Ÿ‡ฉ๐Ÿ‡ฏ'; if($code == 'DK') return '๐Ÿ‡ฉ๐Ÿ‡ฐ'; if($code == 'DM') return '๐Ÿ‡ฉ๐Ÿ‡ฒ'; if($code == 'DO') return '๐Ÿ‡ฉ๐Ÿ‡ด'; if($code == 'DZ') return '๐Ÿ‡ฉ๐Ÿ‡ฟ'; if($code == 'EC') return '๐Ÿ‡ช๐Ÿ‡จ'; if($code == 'EE') return '๐Ÿ‡ช๐Ÿ‡ช'; if($code == 'EG') return '๐Ÿ‡ช๐Ÿ‡ฌ'; if($code == 'EH') return '๐Ÿ‡ช๐Ÿ‡ญ'; if($code == 'ER') return '๐Ÿ‡ช๐Ÿ‡ท'; if($code == 'ES') return '๐Ÿ‡ช๐Ÿ‡ธ'; if($code == 'ET') return '๐Ÿ‡ช๐Ÿ‡น'; if($code == 'FI') return '๐Ÿ‡ซ๐Ÿ‡ฎ'; if($code == 'FJ') return '๐Ÿ‡ซ๐Ÿ‡ฏ'; if($code == 'FK') return '๐Ÿ‡ซ๐Ÿ‡ฐ'; if($code == 'FM') return '๐Ÿ‡ซ๐Ÿ‡ฒ'; if($code == 'FO') return '๐Ÿ‡ซ๐Ÿ‡ด'; if($code == 'FR') return '๐Ÿ‡ซ๐Ÿ‡ท'; if($code == 'GA') return '๐Ÿ‡ฌ๐Ÿ‡ฆ'; if($code == 'GB') return '๐Ÿ‡ฌ๐Ÿ‡ง'; if($code == 'GD') return '๐Ÿ‡ฌ๐Ÿ‡ฉ'; if($code == 'GE') return '๐Ÿ‡ฌ๐Ÿ‡ช'; if($code == 'GF') return '๐Ÿ‡ฌ๐Ÿ‡ซ'; if($code == 'GG') return '๐Ÿ‡ฌ๐Ÿ‡ฌ'; if($code == 'GH') return '๐Ÿ‡ฌ๐Ÿ‡ญ'; if($code == 'GI') return '๐Ÿ‡ฌ๐Ÿ‡ฎ'; if($code == 'GL') return '๐Ÿ‡ฌ๐Ÿ‡ฑ'; if($code == 'GM') return '๐Ÿ‡ฌ๐Ÿ‡ฒ'; if($code == 'GN') return '๐Ÿ‡ฌ๐Ÿ‡ณ'; if($code == 'GP') return '๐Ÿ‡ฌ๐Ÿ‡ต'; if($code == 'GQ') return '๐Ÿ‡ฌ๐Ÿ‡ถ'; if($code == 'GR') return '๐Ÿ‡ฌ๐Ÿ‡ท'; if($code == 'GS') return '๐Ÿ‡ฌ๐Ÿ‡ธ'; if($code == 'GT') return '๐Ÿ‡ฌ๐Ÿ‡น'; if($code == 'GU') return '๐Ÿ‡ฌ๐Ÿ‡บ'; if($code == 'GW') return '๐Ÿ‡ฌ๐Ÿ‡ผ'; if($code == 'GY') return '๐Ÿ‡ฌ๐Ÿ‡พ'; if($code == 'HK') return '๐Ÿ‡ญ๐Ÿ‡ฐ'; if($code == 'HM') return '๐Ÿ‡ญ๐Ÿ‡ฒ'; if($code == 'HN') return '๐Ÿ‡ญ๐Ÿ‡ณ'; if($code == 'HR') return '๐Ÿ‡ญ๐Ÿ‡ท'; if($code == 'HT') return '๐Ÿ‡ญ๐Ÿ‡น'; if($code == 'HU') return '๐Ÿ‡ญ๐Ÿ‡บ'; if($code == 'ID') return '๐Ÿ‡ฎ๐Ÿ‡ฉ'; if($code == 'IE') return '๐Ÿ‡ฎ๐Ÿ‡ช'; if($code == 'IL') return '๐Ÿ‡ฎ๐Ÿ‡ฑ'; if($code == 'IM') return '๐Ÿ‡ฎ๐Ÿ‡ฒ'; if($code == 'IN') return '๐Ÿ‡ฎ๐Ÿ‡ณ'; if($code == 'IO') return '๐Ÿ‡ฎ๐Ÿ‡ด'; if($code == 'IQ') return '๐Ÿ‡ฎ๐Ÿ‡ถ'; if($code == 'IR') return '๐Ÿ‡ฎ๐Ÿ‡ท'; if($code == 'IS') return '๐Ÿ‡ฎ๐Ÿ‡ธ'; if($code == 'IT') return '๐Ÿ‡ฎ๐Ÿ‡น'; if($code == 'JE') return '๐Ÿ‡ฏ๐Ÿ‡ช'; if($code == 'JM') return '๐Ÿ‡ฏ๐Ÿ‡ฒ'; if($code == 'JO') return '๐Ÿ‡ฏ๐Ÿ‡ด'; if($code == 'JP') return '๐Ÿ‡ฏ๐Ÿ‡ต'; if($code == 'KE') return '๐Ÿ‡ฐ๐Ÿ‡ช'; if($code == 'KG') return '๐Ÿ‡ฐ๐Ÿ‡ฌ'; if($code == 'KH') return '๐Ÿ‡ฐ๐Ÿ‡ญ'; if($code == 'KI') return '๐Ÿ‡ฐ๐Ÿ‡ฎ'; if($code == 'KM') return '๐Ÿ‡ฐ๐Ÿ‡ฒ'; if($code == 'KN') return '๐Ÿ‡ฐ๐Ÿ‡ณ'; if($code == 'KP') return '๐Ÿ‡ฐ๐Ÿ‡ต'; if($code == 'KR') return '๐Ÿ‡ฐ๐Ÿ‡ท'; if($code == 'KW') return '๐Ÿ‡ฐ๐Ÿ‡ผ'; if($code == 'KY') return '๐Ÿ‡ฐ๐Ÿ‡พ'; if($code == 'KZ') return '๐Ÿ‡ฐ๐Ÿ‡ฟ'; if($code == 'LA') return '๐Ÿ‡ฑ๐Ÿ‡ฆ'; if($code == 'LB') return '๐Ÿ‡ฑ๐Ÿ‡ง'; if($code == 'LC') return '๐Ÿ‡ฑ๐Ÿ‡จ'; if($code == 'LI') return '๐Ÿ‡ฑ๐Ÿ‡ฎ'; if($code == 'LK') return '๐Ÿ‡ฑ๐Ÿ‡ฐ'; if($code == 'LR') return '๐Ÿ‡ฑ๐Ÿ‡ท'; if($code == 'LS') return '๐Ÿ‡ฑ๐Ÿ‡ธ'; if($code == 'LT') return '๐Ÿ‡ฑ๐Ÿ‡น'; if($code == 'LU') return '๐Ÿ‡ฑ๐Ÿ‡บ'; if($code == 'LV') return '๐Ÿ‡ฑ๐Ÿ‡ป'; if($code == 'LY') return '๐Ÿ‡ฑ๐Ÿ‡พ'; if($code == 'MA') return '๐Ÿ‡ฒ๐Ÿ‡ฆ'; if($code == 'MC') return '๐Ÿ‡ฒ๐Ÿ‡จ'; if($code == 'MD') return '๐Ÿ‡ฒ๐Ÿ‡ฉ'; if($code == 'ME') return '๐Ÿ‡ฒ๐Ÿ‡ช'; if($code == 'MF') return '๐Ÿ‡ฒ๐Ÿ‡ซ'; if($code == 'MG') return '๐Ÿ‡ฒ๐Ÿ‡ฌ'; if($code == 'MH') return '๐Ÿ‡ฒ๐Ÿ‡ญ'; if($code == 'MK') return '๐Ÿ‡ฒ๐Ÿ‡ฐ'; if($code == 'ML') return '๐Ÿ‡ฒ๐Ÿ‡ฑ'; if($code == 'MM') return '๐Ÿ‡ฒ๐Ÿ‡ฒ'; if($code == 'MN') return '๐Ÿ‡ฒ๐Ÿ‡ณ'; if($code == 'MO') return '๐Ÿ‡ฒ๐Ÿ‡ด'; if($code == 'MP') return '๐Ÿ‡ฒ๐Ÿ‡ต'; if($code == 'MQ') return '๐Ÿ‡ฒ๐Ÿ‡ถ'; if($code == 'MR') return '๐Ÿ‡ฒ๐Ÿ‡ท'; if($code == 'MS') return '๐Ÿ‡ฒ๐Ÿ‡ธ'; if($code == 'MT') return '๐Ÿ‡ฒ๐Ÿ‡น'; if($code == 'MU') return '๐Ÿ‡ฒ๐Ÿ‡บ'; if($code == 'MV') return '๐Ÿ‡ฒ๐Ÿ‡ป'; if($code == 'MW') return '๐Ÿ‡ฒ๐Ÿ‡ผ'; if($code == 'MX') return '๐Ÿ‡ฒ๐Ÿ‡ฝ'; if($code == 'MY') return '๐Ÿ‡ฒ๐Ÿ‡พ'; if($code == 'MZ') return '๐Ÿ‡ฒ๐Ÿ‡ฟ'; if($code == 'NA') return '๐Ÿ‡ณ๐Ÿ‡ฆ'; if($code == 'NC') return '๐Ÿ‡ณ๐Ÿ‡จ'; if($code == 'NE') return '๐Ÿ‡ณ๐Ÿ‡ช'; if($code == 'NF') return '๐Ÿ‡ณ๐Ÿ‡ซ'; if($code == 'NG') return '๐Ÿ‡ณ๐Ÿ‡ฌ'; if($code == 'NI') return '๐Ÿ‡ณ๐Ÿ‡ฎ'; if($code == 'NL') return '๐Ÿ‡ณ๐Ÿ‡ฑ'; if($code == 'NO') return '๐Ÿ‡ณ๐Ÿ‡ด'; if($code == 'NP') return '๐Ÿ‡ณ๐Ÿ‡ต'; if($code == 'NR') return '๐Ÿ‡ณ๐Ÿ‡ท'; if($code == 'NU') return '๐Ÿ‡ณ๐Ÿ‡บ'; if($code == 'NZ') return '๐Ÿ‡ณ๐Ÿ‡ฟ'; if($code == 'OM') return '๐Ÿ‡ด๐Ÿ‡ฒ'; if($code == 'PA') return '๐Ÿ‡ต๐Ÿ‡ฆ'; if($code == 'PE') return '๐Ÿ‡ต๐Ÿ‡ช'; if($code == 'PF') return '๐Ÿ‡ต๐Ÿ‡ซ'; if($code == 'PG') return '๐Ÿ‡ต๐Ÿ‡ฌ'; if($code == 'PH') return '๐Ÿ‡ต๐Ÿ‡ญ'; if($code == 'PK') return '๐Ÿ‡ต๐Ÿ‡ฐ'; if($code == 'PL') return '๐Ÿ‡ต๐Ÿ‡ฑ'; if($code == 'PM') return '๐Ÿ‡ต๐Ÿ‡ฒ'; if($code == 'PN') return '๐Ÿ‡ต๐Ÿ‡ณ'; if($code == 'PR') return '๐Ÿ‡ต๐Ÿ‡ท'; if($code == 'PS') return '๐Ÿ‡ต๐Ÿ‡ธ'; if($code == 'PT') return '๐Ÿ‡ต๐Ÿ‡น'; if($code == 'PW') return '๐Ÿ‡ต๐Ÿ‡ผ'; if($code == 'PY') return '๐Ÿ‡ต๐Ÿ‡พ'; if($code == 'QA') return '๐Ÿ‡ถ๐Ÿ‡ฆ'; if($code == 'RE') return '๐Ÿ‡ท๐Ÿ‡ช'; if($code == 'RO') return '๐Ÿ‡ท๐Ÿ‡ด'; if($code == 'RS') return '๐Ÿ‡ท๐Ÿ‡ธ'; if($code == 'RU') return '๐Ÿ‡ท๐Ÿ‡บ'; if($code == 'RW') return '๐Ÿ‡ท๐Ÿ‡ผ'; if($code == 'SA') return '๐Ÿ‡ธ๐Ÿ‡ฆ'; if($code == 'SB') return '๐Ÿ‡ธ๐Ÿ‡ง'; if($code == 'SC') return '๐Ÿ‡ธ๐Ÿ‡จ'; if($code == 'SD') return '๐Ÿ‡ธ๐Ÿ‡ฉ'; if($code == 'SE') return '๐Ÿ‡ธ๐Ÿ‡ช'; if($code == 'SG') return '๐Ÿ‡ธ๐Ÿ‡ฌ'; if($code == 'SH') return '๐Ÿ‡ธ๐Ÿ‡ญ'; if($code == 'SI') return '๐Ÿ‡ธ๐Ÿ‡ฎ'; if($code == 'SJ') return '๐Ÿ‡ธ๐Ÿ‡ฏ'; if($code == 'SK') return '๐Ÿ‡ธ๐Ÿ‡ฐ'; if($code == 'SL') return '๐Ÿ‡ธ๐Ÿ‡ฑ'; if($code == 'SM') return '๐Ÿ‡ธ๐Ÿ‡ฒ'; if($code == 'SN') return '๐Ÿ‡ธ๐Ÿ‡ณ'; if($code == 'SO') return '๐Ÿ‡ธ๐Ÿ‡ด'; if($code == 'SR') return '๐Ÿ‡ธ๐Ÿ‡ท'; if($code == 'SS') return '๐Ÿ‡ธ๐Ÿ‡ธ'; if($code == 'ST') return '๐Ÿ‡ธ๐Ÿ‡น'; if($code == 'SV') return '๐Ÿ‡ธ๐Ÿ‡ป'; if($code == 'SX') return '๐Ÿ‡ธ๐Ÿ‡ฝ'; if($code == 'SY') return '๐Ÿ‡ธ๐Ÿ‡พ'; if($code == 'SZ') return '๐Ÿ‡ธ๐Ÿ‡ฟ'; if($code == 'TC') return '๐Ÿ‡น๐Ÿ‡จ'; if($code == 'TD') return '๐Ÿ‡น๐Ÿ‡ฉ'; if($code == 'TF') return '๐Ÿ‡น๐Ÿ‡ซ'; if($code == 'TG') return '๐Ÿ‡น๐Ÿ‡ฌ'; if($code == 'TH') return '๐Ÿ‡น๐Ÿ‡ญ'; if($code == 'TJ') return '๐Ÿ‡น๐Ÿ‡ฏ'; if($code == 'TK') return '๐Ÿ‡น๐Ÿ‡ฐ'; if($code == 'TL') return '๐Ÿ‡น๐Ÿ‡ฑ'; if($code == 'TM') return '๐Ÿ‡น๐Ÿ‡ฒ'; if($code == 'TN') return '๐Ÿ‡น๐Ÿ‡ณ'; if($code == 'TO') return '๐Ÿ‡น๐Ÿ‡ด'; if($code == 'TR') return '๐Ÿ‡น๐Ÿ‡ท'; if($code == 'TT') return '๐Ÿ‡น๐Ÿ‡น'; if($code == 'TV') return '๐Ÿ‡น๐Ÿ‡ป'; if($code == 'TW') return '๐Ÿ‡น๐Ÿ‡ผ'; if($code == 'TZ') return '๐Ÿ‡น๐Ÿ‡ฟ'; if($code == 'UA') return '๐Ÿ‡บ๐Ÿ‡ฆ'; if($code == 'UG') return '๐Ÿ‡บ๐Ÿ‡ฌ'; if($code == 'UM') return '๐Ÿ‡บ๐Ÿ‡ฒ'; if($code == 'US') return '๐Ÿ‡บ๐Ÿ‡ธ'; if($code == 'UY') return '๐Ÿ‡บ๐Ÿ‡พ'; if($code == 'UZ') return '๐Ÿ‡บ๐Ÿ‡ฟ'; if($code == 'VA') return '๐Ÿ‡ป๐Ÿ‡ฆ'; if($code == 'VC') return '๐Ÿ‡ป๐Ÿ‡จ'; if($code == 'VE') return '๐Ÿ‡ป๐Ÿ‡ช'; if($code == 'VG') return '๐Ÿ‡ป๐Ÿ‡ฌ'; if($code == 'VI') return '๐Ÿ‡ป๐Ÿ‡ฎ'; if($code == 'VN') return '๐Ÿ‡ป๐Ÿ‡ณ'; if($code == 'VU') return '๐Ÿ‡ป๐Ÿ‡บ'; if($code == 'WF') return '๐Ÿ‡ผ๐Ÿ‡ซ'; if($code == 'WS') return '๐Ÿ‡ผ๐Ÿ‡ธ'; if($code == 'XK') return '๐Ÿ‡ฝ๐Ÿ‡ฐ'; if($code == 'YE') return '๐Ÿ‡พ๐Ÿ‡ช'; if($code == 'YT') return '๐Ÿ‡พ๐Ÿ‡น'; if($code == 'ZA') return '๐Ÿ‡ฟ๐Ÿ‡ฆ'; if($code == 'ZM') return '๐Ÿ‡ฟ๐Ÿ‡ฒ'; return '๐Ÿณ'; }