/
device-info.android.ts
36 lines (27 loc) · 1 KB
/
device-info.android.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
declare const java: any;
declare const android: any;
function getContext() {
let ctx = java.lang.Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", null).invoke(null, null);
if (ctx) { return ctx; }
return java.lang.Class.forName("android.app.ActivityThread").getMethod("currentApplication", null).invoke(null, null);
}
export function getDeviceName(): string {
const betterModel = android.provider.Settings.Secure.getString(getContext().getContentResolver(), "bluetooth_name");
if (betterModel) {
return betterModel.toString();
} else {
return this.model;
}
}
export function getModel(): string {
return android.os.Build.MODEL;
}
export function getScreenOrientation(): string {
const context = getContext();
const metrics = new android.util.DisplayMetrics();
const orientation = context.getSystemService(android.content.Context.WINDOW_SERVICE).getDefaultDisplay().getOrientation();
if (orientation % 2 === 0) {
return 'portrait';
}
return 'landscape';
}