Search code examples
androidlocale

Android: Get user language in ISO 639 alpha-2 code(en, pt, jp...)


I'm trying to get user language with two-letters but no success until here.

Use Locale.getDefault().getISO3Language(); returns code with three digits (eng, por, jap).

Use substring method to cut does not work for all codes, so what's the solution?


Solution

  • Instead of getISO3Language(), use getLanguage() and you will get user language like en, ja, pt etc.

    Locale.getDefault().getLanguage();
    

    Checkout official documentation for more information about getLanguage()