Android判断网络状态方法详解
[url]http://zhangkun716717-126-com.iteye.com/blog/813257[/url]
android判断网络的状态断开与否
[url]http://wang-peng1.iteye.com/blog/557362[/url]
[url]http://zhangkun716717-126-com.iteye.com/blog/813257[/url]
public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
boitealerte(this.getString(R.string.alert),
"getSystemService rend null");
} else {//获取所有网络连接信息
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {//逐一查找状态为已连接的网络
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}android判断网络的状态断开与否
[url]http://wang-peng1.iteye.com/blog/557362[/url]

本文详细介绍了如何在Android中使用ConnectivityManager类来判断设备当前的网络状态,包括获取网络连接信息及判断网络是否连接。
1074

被折叠的 条评论
为什么被折叠?



