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]