-
Notifications
You must be signed in to change notification settings - Fork 9
/
判断是否为平板方法
72 lines (65 loc) · 1.93 KB
/
判断是否为平板方法
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
/**
* 判断是否为平板
*
* @return
*/
public static boolean isPad(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
// 屏幕宽度
float screenWidth = display.getWidth();
// 屏幕高度
float screenHeight = display.getHeight();
DisplayMetrics dm = new DisplayMetrics();
display.getMetrics(dm);
double x = Math.pow(dm.widthPixels / dm.xdpi, 2);
double y = Math.pow(dm.heightPixels / dm.ydpi, 2);
// 屏幕尺寸
double screenInches = Math.sqrt(x + y);
// 大于6尺寸则为Pad
if (screenInches >= PAD_SCREEN_INCHES) {
return true;
}
return false;
}
/**
* 判断是否为平板 这里的TelephonyManager在SDK里有如下几种:
*
* SIM_STATE_ABSENT
* SIM_STATE_NETWORK_LOCKED
* SIM_STATE_PIN_REQUIRED
* SIM_STATE_PUK_REQUIRED
* SIM_STATE_READY
* SIM_STATE_UNKNOWN
*
* @param context
* @return
*/
public static boolean isPad(Context context) {
TelephonyManager telephony = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
int type = telephony.getSimState();
Log.i(TAG, "current devices type:" + type);
//没有SIP卡或者无法判断设备默认不给提供打电话功能
if (type == TelephonyManager.SIM_STATE_ABSENT || type == TelephonyManager.SIM_STATE_UNKNOWN ) {
return true;
} else {
return false;
}
}
public boolean isTabletDevice() {
TelephonyManager telephony = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
int type = telephony.getPhoneType();
if (type == TelephonyManager.PHONE_TYPE_NONE) {
Log.i("is Tablet!");
} else {
Log.i("is phone!");
}
return false;
}
这里的PhoneType在SDK里有如下几种:
PHONE_TYPE_NONE
PHONE_TYPE_GSM
PHONE_TYPE_CDMA
PHONE_TYPE_SIP