zoukankan      html  css  js  c++  java
  • Android判断网络是否已经连接

     1 // check all network connect, WIFI or mobile
     2 public static boolean isNetworkAvailable(final Context context) {
     3     boolean hasWifoCon = false;
     4     boolean hasMobileCon = false;
     5  
     6     ConnectivityManager cm = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
     7     NetworkInfo[] netInfos = cm.getAllNetworkInfo();
     8     for (NetworkInfo net : netInfos) {
     9  
    10         String type = net.getTypeName();
    11         if (type.equalsIgnoreCase("WIFI")) {
    12             LevelLogUtils.getInstance().i(tag, "get Wifi connection");
    13             if (net.isConnected()) {
    14                 hasWifoCon = true;
    15             }
    16         }
    17  
    18         if (type.equalsIgnoreCase("MOBILE")) {
    19             LevelLogUtils.getInstance().i(tag, "get Mobile connection");
    20             if (net.isConnected()) {
    21                 hasMobileCon = true;
    22             }
    23         }
    24     }
    25     return hasWifoCon || hasMobileCon;
    26  
    27 }
  • 相关阅读:
    转发和重定向的区别
    关于Daydream VR的最直白的介绍
    Duplicate Protocol Definition of DTService Is Ignored
    automatically select architectures
    java
    初识反射
    java网络编程
    Map接口
    Set,List
    正则表达式
  • 原文地址:https://www.cnblogs.com/lr393993507/p/5542616.html
Copyright © 2011-2022 走看看