1.强制显示或隐藏软件键盘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/**
isOpen = true 显示
isOpen = false 隐藏
当v为空时可以调用getWindow().peekDecorView()获取整个屏幕的View
*/
public
static
void
handlerKeyboard(View v,
boolean
isOpen) {
InputMethodManager imm = (InputMethodManager) v.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
if
(isOpen) {
}
else
{
if
(imm.isActive()) {
imm.hideSoftInputFromWindow(v.getApplicationWindowToken(),
0
);
}
}
}
|
2.判断网络状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/**
返回true网络正常
*/
public
static
boolean
JudgeNetWorkStatus(Context context) {
if
(context ==
null
) {
return
false
;
}
boolean
netStatus =
false
;
ConnectivityManager conManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = conManager.getActiveNetworkInfo();
if
(info !=
null
) {
netStatus = info.isAvailable();
}
return
netStatus;
}
|
3.判断wifi是否 连接
1
2
3
4
5
6
7
8
9
10
11
12
|
public
static
boolean
isWifiConnected(Context context) {
if
(context ==
null
) {
return
false
;
}
ConnectivityManager connMgr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
if
(activeInfo !=
null
&& activeInfo.isConnected()) {
return
activeInfo.getType() == ConnectivityManager.TYPE_WIFI;
}
return
false
;
}
|
4.判断移动网络是否连接
1
2
3
4
5
6
7
8
9
10
11
12
|
public
static
boolean
isMobileConnected(Context context) {
if
(context ==
null
) {
return
false
;
}
ConnectivityManager connMgr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeInfo = connMgr.getActiveNetworkInfo();
if
(activeInfo !=
null
&& activeInfo.isConnected()) {
return
activeInfo.getType() == ConnectivityManager.TYPE_MOBILE;
}
return
false
;
}
|