Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
react-native-device-info
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
放牛的园子
react-native-device-info
Commits
cb06d2ba
Commit
cb06d2ba
authored
Jan 06, 2016
by
Jimmy Mayoukou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use getLanguageTag to retrieve device locale
parent
c89872de
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
12 deletions
+24
-12
RNDeviceModule.java
...c/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
+24
-12
No files found.
android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java
View file @
cb06d2ba
package
com
.
learnium
.
RNDeviceInfo
;
import
javax.annotation.Nullable
;
import
android.bluetooth.BluetoothAdapter
;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.os.Build
;
import
android.provider.Settings.Secure
;
import
com.facebook.react.bridge.ReactApplicationContext
;
import
com.facebook.react.bridge.ReactContextBaseJavaModule
;
import
com.facebook.react.bridge.ReactMethod
;
import
com.facebook.react.bridge.ReadableMap
;
import
com.facebook.react.bridge.ReadableArray
;
import
com.facebook.react.bridge.Callback
;
import
android.os.Build
;
import
android.provider.Settings.Secure
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageInfo
;
import
android.bluetooth.BluetoothAdapter
;
import
java.util.HashMap
;
import
java.util.Locale
;
import
java.util.Map
;
import
javax.annotation.Nullable
;
public
class
RNDeviceModule
extends
ReactContextBaseJavaModule
{
ReactApplicationContext
reactContext
;
...
...
@@ -32,6 +29,21 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
return
"RNDeviceInfo"
;
}
private
String
getCurrentLanguage
()
{
Locale
current
=
getReactApplicationContext
().
getResources
().
getConfiguration
().
locale
;
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
return
current
.
toLanguageTag
();
}
else
{
StringBuilder
builder
=
new
StringBuilder
();
builder
.
append
(
current
.
getLanguage
());
if
(
current
.
getCountry
()
!=
null
)
{
builder
.
append
(
"-"
);
builder
.
append
(
current
.
getCountry
());
}
return
builder
.
toString
();
}
}
@Override
public
@Nullable
Map
<
String
,
Object
>
getConstants
()
{
HashMap
<
String
,
Object
>
constants
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -64,7 +76,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants
.
put
(
"systemVersion"
,
Build
.
VERSION
.
RELEASE
);
constants
.
put
(
"model"
,
Build
.
MODEL
);
constants
.
put
(
"deviceId"
,
Build
.
BOARD
);
constants
.
put
(
"deviceLocale"
,
this
.
reactContext
.
getResources
().
getConfiguration
().
locale
.
toString
());
constants
.
put
(
"deviceLocale"
,
this
.
getCurrentLanguage
());
constants
.
put
(
"uniqueId"
,
Secure
.
getString
(
this
.
reactContext
.
getContentResolver
(),
Secure
.
ANDROID_ID
));
constants
.
put
(
"systemManufacturer"
,
Build
.
MANUFACTURER
);
constants
.
put
(
"bundleId"
,
packageName
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment