3

I want to use the Locale method forLanguageTag().

However, the device minSdk that is required for using it is 21.

Since I want my app to be compatible with as many devices as possible, I need an equivalent for lower minSdk.

Is anybody familiar with such alternative?

Lior L
  • 49
  • 1
  • 1
  • 7

2 Answers2

1

Add Apache Commons Lang packet by adding this to build.gradle:

compile 'org.apache.commons:commons-lang3:3.6'

Use this function:

LocaleUtils.toLocale(localeString)
Henning Hall
  • 1,297
  • 2
  • 11
  • 31
1

Or use Locale("languageTag", "countryCode") straight away if it's possible for your case - not the same, but was alternative for mine.

Additional compile 'org.apache.commons:commons-langX:Y.Z' dependency gives you more than 3k LOC, at least in 2014, source: https://www.contentful.com/blog/2014/10/30/android-and-the-dex-64k-methods-limit/

PrzemekTom
  • 1,328
  • 1
  • 13
  • 34