Commit da905ad6 authored by Daehoon Kim's avatar Daehoon Kim Committed by Mehdi Achour

Support deprecated accessing locale directly on Android (#426)

* Support deprecated locale access on Android

* Add change log
parent 41a429aa
......@@ -2,6 +2,12 @@
### next
### 0.22.1
* Fix deprecated code on Android in the following methods (https://github.com/rebeccahughes/react-native-device-info/pull/426)
* getDeviceCountry
* getDeviceLocale
### 0.22.0
* Add support for `getIpAddress` and `getMacAddress` on iOS (https://github.com/rebeccahughes/react-native-device-info/commit/41735bd0b2efe1f626afc066604f27073acb9d4c)
......
......@@ -67,7 +67,13 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
}
private String getCurrentLanguage() {
Locale current = getReactApplicationContext().getResources().getConfiguration().locale;
Locale current;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
current = getReactApplicationContext().getResources().getConfiguration().getLocales().get(0);
} else {
current = getReactApplicationContext().getResources().getConfiguration().locale;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return current.toLanguageTag();
} else {
......@@ -82,7 +88,13 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
}
private String getCurrentCountry() {
Locale current = getReactApplicationContext().getResources().getConfiguration().locale;
Locale current;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
current = getReactApplicationContext().getResources().getConfiguration().getLocales().get(0);
} else {
current = getReactApplicationContext().getResources().getConfiguration().locale;
}
return current.getCountry();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment