Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"getDisplayLanguage()" always returning "English"

Tags:

android

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

like image 775
x-27 Avatar asked Nov 06 '22 15:11

x-27


1 Answers

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 :)

like image 192
Swati Avatar answered Nov 14 '22 23:11

Swati