5

I need to get the current language selected in the Android device. When I use below code:

Log.v("Language: ", Locale.getDefault().getDisplayLanguage());
Log.v("Language: ", getResources().getConfiguration().locale.getDisplayLanguage());

The output is always same:

V/Language:: English

Below picture from android emulator selected language:

android emulator selected language

When I change the language of emulator, I can get the logs in the picture on the Android console.(But getDisplayLanguage() function returning English)

android console

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
x-27
  • 81
  • 7
  • Locale.getDefault() always return english because default of android language is english ;) remove getDefault() and check it – niceumang Jul 09 '19 at 06:51

1 Answers1

1
String locale = context.getResources().getConfiguration().locale.getDisplayName();
String locale = java.util.Locale.getDefault().getDisplayName();

They are different. The first can change if the user switches the Locale.

The second is the one that is pre-installed on the phone. It never changes no matter what the user does.

Happy Coding :)

Swati
  • 146
  • 1
  • 10
  • My result hasn't changed. If you tried it and it works correctly, the error is probably in my emulator. – x-27 Jul 09 '19 at 07:07
  • Kindly refer this, https://stackoverflow.com/questions/8690460/how-to-get-language-locale-currently-android-app-displays Hope this helps you... :) – Swati Jul 09 '19 at 09:28