-
Notifications
You must be signed in to change notification settings - Fork 803
/
AppSysMgr.java
973 lines (859 loc) · 27.3 KB
/
AppSysMgr.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
package com.jingewenku.abrahamcaijin.commonutil;
import android.Manifest;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Vibrator;
import android.provider.Settings;
import android.telephony.CellLocation;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.WindowManager;
import android.webkit.WebView;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.UUID;
/**
* 主要功能: 获取App应用系统基本信息
*
* @Prject: CommonUtilLibrary
* @Package: com.jingewenku.abrahamcaijin.commonutil
* @author: AbrahamCaiJin
* @date: 2017年05月04日 14:13
* @Copyright: 个人版权所有
* @Company:
* @version: 1.0.0
*/
@SuppressWarnings("deprecation")
public class AppSysMgr {
public static final int DEFAULT_THREAD_POOL_SIZE = getSysDefaultThreadPoolSize();
/**
* 获得客户端操作系统名称
* @return
*/
public static String getSysClientOs() {
String OsName = android.os.Build.ID;
return OsName;
}
/**
* 获取当前操作系统的sdk版本
* @return String 系统SDK版本
*/
public static String getSysSdk() {
String sdkVersion = android.os.Build.VERSION.SDK;
AppLogMessageMgr.i("AppSysMgr-->>getSysLanguage", sdkVersion);
return sdkVersion;
}
/**
* 获取当前操作系统的语言
* @return String 系统语言
*/
public static String getSysLanguage() {
String language = Locale.getDefault().getLanguage();
AppLogMessageMgr.i("AppSysMgr-->>getSysLanguage", language);
return language;
}
/**
* 获取当前系统上的语言列表(Locale列表)
*
* @return 语言列表
*/
public static Locale[] getSystemLanguageList() {
return Locale.getAvailableLocales();
}
/**
* 获取手机型号
* @return String 手机型号
*/
public static String getSysModel() {
String model = android.os.Build.MODEL;
AppLogMessageMgr.i("AppSysMgr-->>getSysModel", model);
return model;
}
/**
* 获取操作系统的版本号
* @return String 系统版本号
*/
public static String getSysRelease() {
String release = android.os.Build.VERSION.RELEASE;
AppLogMessageMgr.i("AppSysMgr-->>getSysRelease", release);
return release;
}
/**
* 读取SIM卡序列号
* @param content 上下文
* @return String SIM卡序列号
*/
public static String getSysSIMSerialNum(Context content) {
String simSerialNumber = getSysTelephonyManager(content).getSimSerialNumber();
AppLogMessageMgr.i("AppSysMgr-->>getSysSIMSerialNum", simSerialNumber);
return simSerialNumber;
}
/**
* 获取手机CPU序列号
* @return String cpu序列号(16位) 读取失败为"0000000000000000"
*/
public static String getSysCPUSerialNum() {
String str = "", strCPU = "", cpuSerialNum = "0000000000000000";
try {
//读取CPU信息
Process pp = Runtime.getRuntime().exec("cat/proc/cpuinfo");
InputStreamReader ir = new InputStreamReader(pp.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
//查找CPU序列号
for (int i = 1; i < 100; i++) {
str = input.readLine();
if (str != null) {
//查找到序列号所在行
if (str.indexOf("Serial") > -1) {
//提取序列号
strCPU = str.substring(str.indexOf(":") + 1,
str.length());
//去空格
cpuSerialNum = strCPU.trim();
break;
}
}else{
break;
}
}
} catch (IOException e) {
e.printStackTrace();
AppLogMessageMgr.e("AppSysMgr-->>getSysCPUSerialNum", e.getMessage().toString());
}
return cpuSerialNum;
}
/**
* 获得电话管理实例对象
* @param content 上下文
* @return TelephonyManager 电话管理实例对象
*/
private static TelephonyManager getSysTelephonyManager(Context content) {
TelephonyManager telephonyManager = null;
telephonyManager = (TelephonyManager) content.getSystemService(Context.TELEPHONY_SERVICE);
AppLogMessageMgr.i("AppSysMgr-->>getSysTelephonyManager", telephonyManager + "");
return telephonyManager;
}
/**
* 读唯一的设备ID(唯一的设备ID【GSM手机的IMEI】和【CDMA手机的 MEID】,如果获取不到返回一个默认字符串)
* @param content 上下文
* @return String 获取设备序列号
*/
public static String getSysTelephoneSerialNum(Context content) {
String deviceId = getSysTelephonyManager(content).getDeviceId();
AppLogMessageMgr.i("AppSysMgr-->>getSysTelephoneSerialNum", deviceId + "");
return deviceId;
}
/**
* 获取运营商信息(三大运营商)
* @param content 上下文
* @return String 获取运营商名称
*/
public static String getSysCarrier(Context content) {
String moblieType = "";
TelephonyManager telephonyManager = (TelephonyManager) content.getSystemService(Context.TELEPHONY_SERVICE);
String imsi = telephonyManager.getSubscriberId();
if (imsi != null && imsi.length() > 0) {
//因为移动网络编号46000下的IMSI已经用完,所以虚拟了一个46002编号,134/159号段使用了此编号
if (imsi.startsWith("46000") || imsi.startsWith("46002")) {
//中国移动
moblieType = "China Mobile";
} else if (imsi.startsWith("46001")) {
//中国联通
moblieType = "China Unicom";
} else if (imsi.startsWith("46003")) {
//中国电信
moblieType = "China Telecom";
}
}
AppLogMessageMgr.i("AppSysMgr-->>getSysCarrier", moblieType);
return moblieType;
}
/**
* 获取手机状态(0:无活动 1:响铃 2:待机)
* @param context 上下文
* @return Integer 手机状态
*/
public static Integer getSysPhoneState(Context context) {
Integer callState = getSysTelephonyManager(context).getCallState();
AppLogMessageMgr.i("AppSysMgr-->>getSysPhoneState", callState + "");
return callState;
}
/**
* 获得手机方位
* @param context 上下文
* @return CellLocation 手机方位
*/
public static CellLocation getSysPhoneLoaction(Context context) {
CellLocation cellLocation = getSysTelephonyManager(context).getCellLocation();
AppLogMessageMgr.i("AppSysMgr-->>getSysPhoneLoaction", cellLocation + "");
return cellLocation;
}
/**
* 获得设备的软件版本号(注:the IMEI/SV(software version) for GSM phones 不支持返回“not available”)
* @param context 上下文
* @return String 设备软件版本号
*/
public static String getSysDeviceSoftVersion(Context context) {
String deviceSoftwareVersion = getSysTelephonyManager(context).getDeviceSoftwareVersion();
AppLogMessageMgr.i("AppSysMgr-->>getSysDeviceSoftVersion", deviceSoftwareVersion + "");
return deviceSoftwareVersion;
}
/**
* 获得手机号
* @param context 上下文
* @return String 手机号
*/
public static String getSysPhoneNumber(Context context) {
String phoneNumber = getSysTelephonyManager(context).getLine1Number();
AppLogMessageMgr.i("AppSysMgr-->>getSysPhoneNumber", phoneNumber + "");
return phoneNumber;
}
/**
* 获得SIM卡提供的移动国家码和移动网络码.5或6位的十进制数字。(注:SIM卡的状态必须是 SIM_STATE_READY(使用getSimState()判断))
* @param context 上下文
* @return String SIM移动国家编码和移动网络编码
*/
public static String getSysSimCode(Context context) {
String code = "";
if (getSysTelephonyManager(context).getSimState() == 5) {
code = getSysTelephonyManager(context).getSimOperator();
}
AppLogMessageMgr.i("AppSysMgr-->>getSysSimCode", code + "");
return code;
}
/**
* 服务商名称(注:例如:中国移动、联通SIM卡的状态必须是 SIM_STATE_READY(使用getSimState()判断)).
* @param context 上下文
* @return String 服务商名称
*/
public static String getSysSimPrivatorName(Context context) {
String simOperatorName = "";
if (getSysTelephonyManager(context).getSimState() == 5) {
simOperatorName = getSysTelephonyManager(context).getSimOperatorName();
}
AppLogMessageMgr.i("AppSysMgr-->>getSysSimPrivatorName", simOperatorName);
return simOperatorName;
}
/**
* 唯一的用户ID (注:例如:IMSI(国际移动用户识别码) for a GSM phone. 需要权限:READ_PHONE_STATE)
* @param context 上下文
* @return String 获取国际移动用户GSM识别码
*/
public static String getSysUserPhoneId(Context context) {
String subscriberId = getSysTelephonyManager(context).getSubscriberId();
AppLogMessageMgr.i("AppSysMgr-->>getSysUserPhoneId", subscriberId);
return subscriberId;
}
/**
* 获取WindowManager对象
* @param context 上下文对象
* @return WindowManager
*/
public static WindowManager getWindowManager(Context context){
return (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}
/**
* 获取屏幕管理类
* @param activity activity对象
* @return DisplayMetrics 屏幕管理实例
*/
public static DisplayMetrics getSysDisplayMetrics(Activity activity) {
DisplayMetrics displayMetrics = null;
if (displayMetrics == null) {
displayMetrics = new DisplayMetrics();
}
activity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
AppLogMessageMgr.i("AppSysMgr-->>getSysDisplayMetrics", "获取屏幕管理对象为:" + displayMetrics);
return displayMetrics;
}
/**
* 获取屏幕宽度和高度并返回数组
* @param context 上下文对象
* @return int[] 宽和高
*/
public static int[] getScreenDispaly(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//手机屏幕的宽度
int width = wm.getDefaultDisplay().getWidth();
//手机屏幕的高度
int height = wm.getDefaultDisplay().getHeight();
AppLogMessageMgr.i("AppSysMgr-->>getScreenDispaly-->>width", "获取屏幕宽度为:" + width);
AppLogMessageMgr.i("AppSysMgr-->>getScreenDispaly-->>height", "获取屏幕高度为:" + height);
int result[] = { width, height };
return result;
}
/**
* 获取屏幕宽度和高度并返回数组
* @param context 上下文对象
* @return int[] 宽和高
*/
public static int[] getScreenDispaly8(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//手机屏幕的宽度
int width = wm.getDefaultDisplay().getWidth() /10 * 8;
//手机屏幕的高度
int height = wm.getDefaultDisplay().getHeight() /10 * 8;
AppLogMessageMgr.i("AppSysMgr-->>getScreenDispaly-->>width", "获取屏幕宽度为:" + width);
AppLogMessageMgr.i("AppSysMgr-->>getScreenDispaly-->>height", "获取屏幕高度为:" + height);
int result[] = { width, height };
return result;
}
/**
* 获取屏幕宽度
* @param context 上下文对象
* @return Integer 屏幕宽度
*/
public static Integer getSysScreenWidth(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics displayMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(displayMetrics);
AppLogMessageMgr.i("AppSysMgr-->>getSysScreenWidth", "获取屏幕宽度为:" + displayMetrics.widthPixels);
return displayMetrics.widthPixels;
}
/**
* 获取屏幕高度
* @param context 上下文对象
* @return Integer 屏幕高度
*/
public static Integer getSysScreenHeight(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics displayMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(displayMetrics);
AppLogMessageMgr.i("AppSysMgr-->>getSysScreenHeight", "获取屏幕高度为:" + displayMetrics.heightPixels);
return displayMetrics.heightPixels;
}
/**
* 获取屏幕状态栏目高度
* @param context 上下文对象
* @return Integer 状态栏高度
*/
public static Integer getSysScreenStatusHeight(Context context) {
int statusHeight = 0;
try {
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
statusHeight = context.getResources().getDimensionPixelSize(height);
AppLogMessageMgr.i("AppSysMgr-->>getSysScreenStatusHeight", "获取屏幕状态栏高度为:" + statusHeight);
} catch (Exception e) {
e.printStackTrace();
AppLogMessageMgr.e("AppSysMgr-->>getSysScreenStatusHeight", "获取屏幕状态栏高度失败!" + e.getMessage());
}
return statusHeight;
}
/**
* 获得系统配置相符的线程池大小
* @return Integer 返回系统配置相符合线程大小
*/
public static Integer getSysDefaultThreadPoolSize() {
Integer availableProcessors = 2 * Runtime.getRuntime().availableProcessors() + 1;
availableProcessors = availableProcessors > 8 ? 8 : availableProcessors;
AppLogMessageMgr.i("AppSysMgr-->>getSysDefaultThreadPoolSize", availableProcessors + "");
return availableProcessors;
}
/**
* 获取当前APP应用的SampleSize大小
* @param options BitmapFactory.Options对象
* @param minSideLength 计算最小值
* @param maxNumOfPixels 计算最大值
* @return Integer 返回SampleSize大小
*/
public static Integer getSysSampleSize(BitmapFactory.Options options, int minSideLength, int maxNumOfPixels) {
Integer initialSize = calculateSysInitialSampleSize(options, minSideLength, maxNumOfPixels);
Integer roundedSize;
if (initialSize <= 8 ) {
roundedSize = 1;
while (roundedSize < initialSize) {
roundedSize <<= 1;
}
}else{
roundedSize = (initialSize + 7) / 8 * 8;
}
AppLogMessageMgr.i("AppSysMgr-->>getSysSampleSize", roundedSize + "");
return roundedSize;
}
/**
* 计算公式
* @param options BitmapFactory.Options对象
* @param minSideLength 计算最小值
* @param maxNumOfPixels 计算最大值
* @return Integer
*/
private static Integer calculateSysInitialSampleSize(BitmapFactory.Options options,int minSideLength, int maxNumOfPixels) {
double w = options.outWidth;
double h = options.outHeight;
Integer lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels));
Integer upperBound = (minSideLength == -1) ? 128 : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength));
if (upperBound < lowerBound) {
return lowerBound;
}
if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
return 1;
} else if (minSideLength == -1) {
return lowerBound;
} else {
return upperBound;
}
}
/**
* 获取震动器对象
* @param context 上下文对象
* @return Vibrator 震动器对象
*/
public static Vibrator getVibrator(Context context){
return (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
}
/**
* 获取手机IP地址
* @return String 手机IP地址
*/
public String getSysLocalIpAddress() {
String hostAddress = null;
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
hostAddress = inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
AppLogMessageMgr.e("AppSysMgr-->>getSysLocalIpAddress", e.getMessage().toString());
}
AppLogMessageMgr.i("AppSysMgr-->>getSysLocalIpAddress", hostAddress);
return hostAddress;
}
/**
*获取AndroidID
* @param ctx
* @return
*/
public static String getAndroidID(Context ctx) {
return Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
}
/**
* 获取设备IMSI码
* @param ctx
* @return
*/
public static String getIMSI(Context ctx) {
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
return tm.getSubscriberId() != null ? tm.getSubscriberId() : null;
}
/**
* 获取网络IP地址(优先获取wifi地址)
* @param ctx
* @return
*/
public static String getIP(Context ctx) {
WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
return wifiManager.isWifiEnabled() ? getWifiIP(wifiManager) : getGPRSIP();
}
/**
* 获取WIFI连接下的ip地址
* @param wifiManager
* @return
*/
public static String getWifiIP(WifiManager wifiManager) {
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ip = intToIp(wifiInfo.getIpAddress());
return ip != null ? ip : "";
}
/**
* 获取GPRS连接下的ip地址
* @return
*/
public static String getGPRSIP() {
String ip = null;
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
for (Enumeration<InetAddress> enumIpAddr = en.nextElement().getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
ip = inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
ip = null;
}
return ip;
}
private static String intToIp(int i) {
return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF) + "." + (i >> 24 & 0xFF);
}
/**
* 获取设备序列号
* @return
*/
public static String getSerial() {
return Build.SERIAL;
}
/**
* 获取SIM序列号
* @param ctx
* @return
*/
public static String getSIMSerial(Context ctx) {
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
return tm.getSimSerialNumber();
}
/**
* 获取网络运营商 46000,46002,46007 中国移动,46001 中国联通,46003 中国电信
* @param ctx
* @return
*/
public static String getMNC(Context ctx) {
String providersName = "";
TelephonyManager telephonyManager = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
if (telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
providersName = telephonyManager.getSimOperator();
providersName = providersName == null ? "" : providersName;
}
return providersName;
}
/**
* 获取网络运营商:中国电信,中国移动,中国联通
* @param ctx
* @return
*/
public static String getCarrier(Context ctx) {
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
return tm.getNetworkOperatorName().toLowerCase(Locale.getDefault());
}
/**
* 获取硬件型号
* @return
*/
public static String getModel() {
return Build.MODEL;
}
/**
* 获取编译厂商
* @return
*/
public static String getBuildBrand() {
return Build.BRAND;
}
/**
*获取编译服务器主机
* @return
*/
public static String getBuildHost() {
return Build.HOST;
}
/**
*获取描述Build的标签
* @return
*/
public static String getBuildTags() {
return Build.TAGS;
}
/**
*获取系统编译时间
* @return
*/
public static long getBuildTime() {
return Build.TIME;
}
/**
*获取系统编译作者
* @return
*/
public static String getBuildUser() {
return Build.USER;
}
/**
*获取编译系统版本(5.1)
* @return
*/
public static String getBuildVersionRelease() {
return Build.VERSION.RELEASE;
}
/**
*获取开发代号
* @return
*/
public static String getBuildVersionCodename() {
return Build.VERSION.CODENAME;
}
/**
* 获取源码控制版本号
* @return
*/
public static String getBuildVersionIncremental() {
return Build.VERSION.INCREMENTAL;
}
/**
*获取编译的SDK
* @return
*/
public static int getBuildVersionSDK() {
return Build.VERSION.SDK_INT;
}
/**
*获取修订版本列表(LMY47D)
* @return
*/
public static String getBuildID() {
return Build.ID;
}
/**
*CPU指令集
* @return
*/
public static String[] getSupportedABIS() {
String[] result = new String[]{"-"};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
result = Build.SUPPORTED_ABIS;
}
if (result == null || result.length == 0) {
result = new String[]{"-"};
}
return result;
}
/**
*获取硬件制造厂商
* @return
*/
public static String getManufacturer() {
return Build.MANUFACTURER;
}
/**
*获取系统启动程序版本号
* @return
*/
public static String getBootloader() {
return Build.BOOTLOADER;
}
/**
*
* @param ctx
* @return
*/
public static String getScreenDisplayID(Context ctx) {
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
return String.valueOf(wm.getDefaultDisplay().getDisplayId());
}
/**
* 获取系统版本号
* @return
*/
public static String getDisplayVersion() {
return Build.DISPLAY;
}
/**
*获取语言
* @return
*/
public static String getLanguage() {
return Locale.getDefault().getLanguage();
}
/**
* 获取国家
* @param ctx
* @return
*/
public static String getCountry(Context ctx) {
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
Locale locale = Locale.getDefault();
return tm.getSimState() == TelephonyManager.SIM_STATE_READY ? tm.getSimCountryIso().toLowerCase(Locale.getDefault()) : locale.getCountry().toLowerCase(locale);
}
/**
*获取系统版本:5.1.1
* @return
*/
public static String getOSVersion() {
return Build.VERSION.RELEASE;
}
/**
*获取GSF序列号
* @param context
* @return
*/
//<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
public static String getGSFID(Context context) {
String result;
final Uri URI = Uri.parse("content://com.google.android.gsf.gservices");
final String ID_KEY = "android_id";
String[] params = {ID_KEY};
Cursor c = context.getContentResolver().query(URI, null, null, params, null);
if (c == null || !c.moveToFirst() || c.getColumnCount() < 2) {
return null;
} else {
result = Long.toHexString(Long.parseLong(c.getString(1)));
}
c.close();
return result;
}
/**
* 获取蓝牙地址
* @param context
* @return
*/
//<uses-permission android:name="android.permission.BLUETOOTH"/>
@SuppressWarnings("MissingPermission")
public static String getBluetoothMAC(Context context) {
String result = null;
try {
if (context.checkCallingOrSelfPermission(Manifest.permission.BLUETOOTH)
== PackageManager.PERMISSION_GRANTED) {
BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
result = bta.getAddress();
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* Android设备物理唯一标识符
* @return
*/
public static String getPsuedoUniqueID() {
String devIDShort = "35" + (Build.BOARD.length() % 10) + (Build.BRAND.length() % 10);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
devIDShort += (Build.SUPPORTED_ABIS[0].length() % 10);
} else {
devIDShort += (Build.CPU_ABI.length() % 10);
}
devIDShort += (Build.DEVICE.length() % 10) + (Build.MANUFACTURER.length() % 10) + (Build.MODEL.length() % 10) + (Build.PRODUCT.length() % 10);
String serial;
try {
serial = Build.class.getField("SERIAL").get(null).toString();
return new UUID(devIDShort.hashCode(), serial.hashCode()).toString();
} catch (Exception e) {
serial = "ESYDV000";
}
return new UUID(devIDShort.hashCode(), serial.hashCode()).toString();
}
/**
* 构建标识,包括brand,name,device,version.release,id,version.incremental,type,tags这些信息
* @return
*/
public static String getFingerprint() {
return Build.FINGERPRINT;
}
/**
* 获取硬件信息
* @return
*/
public static String getHardware() {
return Build.HARDWARE;
}
/**
* 获取产品信息
* @return
*/
public static String getProduct() {
return Build.PRODUCT;
}
/**
* 获取设备信息
* @return
*/
public static String getDevice() {
return Build.DEVICE;
}
/**
* 获取主板信息
* @return
*/
public static String getBoard() {
return Build.BOARD;
}
/**
* 获取基带版本(无线电固件版本 Api14以上)
* @return
*/
public static String getRadioVersion() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH ? Build.getRadioVersion() : "";
}
/**
* 获取的浏览器指纹(User-Agent)
* @param ctx
* @return
*/
public static String getUA(Context ctx) {
final String system_ua = System.getProperty("http.agent");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return new WebView(ctx).getSettings().getDefaultUserAgent(ctx) + "__" + system_ua;
} else {
return new WebView(ctx).getSettings().getUserAgentString() + "__" + system_ua;
}
}
/**
* 获取得屏幕密度
* @param ctx
* @return
*/
public static String getDensity(Context ctx) {
String densityStr = null;
final int density = ctx.getResources().getDisplayMetrics().densityDpi;
switch (density) {
case DisplayMetrics.DENSITY_LOW:
densityStr = "LDPI";
break;
case DisplayMetrics.DENSITY_MEDIUM:
densityStr = "MDPI";
break;
case DisplayMetrics.DENSITY_TV:
densityStr = "TVDPI";
break;
case DisplayMetrics.DENSITY_HIGH:
densityStr = "HDPI";
break;
case DisplayMetrics.DENSITY_XHIGH:
densityStr = "XHDPI";
break;
case DisplayMetrics.DENSITY_400:
densityStr = "XMHDPI";
break;
case DisplayMetrics.DENSITY_XXHIGH:
densityStr = "XXHDPI";
break;
case DisplayMetrics.DENSITY_XXXHIGH:
densityStr = "XXXHDPI";
break;
}
return densityStr;
}
/**
* 获取google账号
* @param ctx
* @return
*/
//<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
@SuppressWarnings("MissingPermission")
public static String[] getGoogleAccounts(Context ctx) {
if (ctx.checkCallingOrSelfPermission(Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) {
Account[] accounts = AccountManager.get(ctx).getAccountsByType("com.google");
String[] result = new String[accounts.length];
for (int i = 0; i < accounts.length; i++) {
result[i] = accounts[i].name;
}
return result;
}
return null;
}
}