关于android网络连接判断

来源:互联网 发布:360浏览器 网络收藏夹 编辑:程序博客网 时间:2024/05/17 08:23

最近在做一个应用,需要判断当前是否能够访问网络。在网上很多地方有判断的方法。

public static boolean isNetworkAvailable(Context context) {      boolean netSataus = false;      ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);      NetworkInfo netinfo = cm.getActiveNetworkInfo();      if (netinfo != null) {          netSataus = netinfo.isAvailable();      }      return netSataus;  } 

以上是网上的方法。但是,以上的方法并不能真正的判断出来。如果我连接上了wifi,但是这个wifi并不能访问网络。此时上面的方法也是返回的true.

1 0
原创粉丝点击