zoukankan      html  css  js  c++  java
  • Android检测wifi网络的连接情况

     1 public static boolean isWifiConnected(Context context)
     2 {
     3     ConnectivityManager connectivityManager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
     4     NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
     5     if(wifiNetworkInfo.isConnected())
     6     {
     7         return true ;
     8     }
     9  
    10     return false ;
    11 }
    ConnectivityManager 类中封装了和链接相关的(Wi-Fi, GPRS, UMTS, etc)相关的方法和类,能够检测当前的连接状态。

    1  WifiManager wifiMgr = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    2     int state = wifiMgr.getWifiState();
    3     if (state == WifiManager.WIFI_STATE_ENABLED || state == WifiManager.WIFI_STATE_ENABLING) {
    4     return true;
    5     } else {
    6     return false;
    7     }
    This class provides the primary API for managing all aspects of Wi-Fi connectivity. Get an instance of this class by calling Context.getSystemService(Context.WIFI_SERVICE). It deals with several categories of items:
    
    The list of configured networks. The list can be viewed and updated, and attributes of individual entries can be modified.
    The currently active Wi-Fi network, if any. Connectivity can be established or torn down, and dynamic information about the state of the network can be queried.
    Results of access point scans, containing enough information to make decisions about what access point to connect to.
    It defines the names of various Intent actions that are broadcast upon any sort of change in Wi-Fi state.
    This is the API to use when performing Wi-Fi specific operations. To perform operations that pertain to network connectivity at an abstract level, use android.net.ConnectivityManager.

    总之  ConnectivityManager主要管理和网络连接相关的操作,而WifiManager主要管理和Wifi相关的操作。

  • 相关阅读:
    HTTp状态详解
    考虑实现一个web报表制作工具
    UCML编译型应用框架快速开发工具体系介绍
    SQL Server 2000 SP4发布
    有几个mywallop的邀请,想要看看的给我留言吧
    写给刚接触Web Service的朋友
    国内完全免费的电子书籍下载,大家可以上去淘淘宝
    c#高性能在WEB端产生验证图片
    在.net中使用xmlhttp组件读取网页源码
    Oracle经典书籍介绍
  • 原文地址:https://www.cnblogs.com/zhouliweiblog/p/2764022.html
Copyright © 2011-2022 走看看