7

I am trying to return the locale in my app with this line of code:

Locale current = getResources().getConfiguration().locale; 

The minSdkVersion is 15 and compiling with 24. But locale is deprecated, does it affect my app efficiency?

Is there any other 'not deprecated' way to retrieve the locale?

2

1 Answer 1

14

If you are compiling with API 24 or above you should do this. Still it will show deprecated for lower one but you can ignore that.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { locale = getResources().getConfiguration().getLocales().get(0); } else { locale = getResources().getConfiguration().locale; } 
Sign up to request clarification or add additional context in comments.

2 Comments

thank you, this is exactly the answer that I wanted :)
Warning: N returns a list of locales, and loading strings will try to fallback to the next locale if there are no resources available. So just looking at the first one might be meaningless.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.