Detect Android 4.0 and 7.0 language

0

For an application, with the intention of detecting when the device is in Spanish, I used the following if :

if(Locale.getDefault().getLanguage()=="es")

However, although this has worked for me in the Android Studio (7.0) emulator, changing the language of the device from the settings and opening the app in different situations, in 4.0 it does not detect Spanish in this way, so always goes through else .

For this reason I would like to know if this method can be used with all the versions, if not, which one should be used and otherwise what is wrong so that sometimes it works and sometimes it does not.

    
asked by pepito 07.07.2017 в 07:40
source

1 answer

2

Change if(Locale.getDefault().getLanguage()=="es") to

if("es".equals(Locale.getDefault().getLanguage()))

The Strings in Java should not be compared with == , but with the equals method.

You should take a look at this question for more information.

    
answered by 07.07.2017 / 08:45
source