UNPKG

2.7 kBJavaScriptView Raw
1import { Application } from '../../application';
2import { SDK_VERSION } from '../../utils/constants';
3import { platformNames } from '../common';
4import { Screen } from '../screen';
5const MIN_TABLET_PIXELS = 600;
6class DeviceRef {
7 get manufacturer() {
8 if (!this._manufacturer) {
9 this._manufacturer = android.os.Build.MANUFACTURER;
10 }
11 return this._manufacturer;
12 }
13 get os() {
14 return platformNames.android;
15 }
16 get osVersion() {
17 if (!this._osVersion) {
18 this._osVersion = android.os.Build.VERSION.RELEASE;
19 }
20 return this._osVersion;
21 }
22 get model() {
23 if (!this._model) {
24 this._model = android.os.Build.MODEL;
25 }
26 return this._model;
27 }
28 get sdkVersion() {
29 if (!this._sdkVersion) {
30 this._sdkVersion = android.os.Build.VERSION.SDK;
31 }
32 return this._sdkVersion;
33 }
34 get deviceType() {
35 if (!this._deviceType) {
36 const dips = Math.min(Screen.mainScreen.widthPixels, Screen.mainScreen.heightPixels) / Screen.mainScreen.scale;
37 // If the device has more than 600 dips it is considered to be a tablet.
38 if (dips >= MIN_TABLET_PIXELS) {
39 this._deviceType = 'Tablet';
40 }
41 else {
42 this._deviceType = 'Phone';
43 }
44 }
45 return this._deviceType;
46 }
47 get uuid() {
48 if (!this._uuid) {
49 const nativeApp = Application.android.getNativeApplication();
50 this._uuid = android.provider.Settings.Secure.getString(nativeApp.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
51 }
52 return this._uuid;
53 }
54 get language() {
55 let defaultNativeLocale;
56 if (SDK_VERSION >= 24) {
57 defaultNativeLocale = android.content.res.Resources.getSystem().getConfiguration().getLocales().get(0);
58 }
59 else {
60 defaultNativeLocale = android.content.res.Resources.getSystem().getConfiguration().locale;
61 }
62 return defaultNativeLocale.getLanguage().replace('_', '-');
63 }
64 get region() {
65 let defaultNativeLocale;
66 if (SDK_VERSION >= 24) {
67 defaultNativeLocale = android.content.res.Resources.getSystem().getConfiguration().getLocales().get(0);
68 }
69 else {
70 defaultNativeLocale = android.content.res.Resources.getSystem().getConfiguration().locale;
71 }
72 return defaultNativeLocale.getCountry();
73 }
74}
75export const Device = new DeviceRef();
76// This retains compatibility with NS6
77export const device = Device;
78//# sourceMappingURL=index.android.js.map
\No newline at end of file