本帖最后由 清风夜独醉 于 2014-4-23 19:40 编辑
一、判断网络连接是否可用
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm == null) {
} else {
NetworkInfo[] info = cm.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
二、判断当前网络连接是否是wifi链接
public static boolean isWifiNetwor(Context context) {
ConnectivityManager con = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean wifi = con.getNetworkInfo(ConnectivityManager.)
.isConnectedOrConnecting();
return wifi;
}
|