Package 

Class NetworkUtils

    • Method Summary

      Modifier and Type Method Description
      static void openNetSetting(Activity activity) 打开网络设置界面
      static NetworkInfo.State getCurrentNetworkState(Context context) 获取当前网络的状态
      static boolean isConnectedByState(Context context) 判断当前网络是否已经连接
      static boolean isConnectingByState(Context context) 判断当前网络是否正在连接
      static boolean isDisconnectedByState(Context context) 判断当前网络是否已经断开
      static boolean isDisconnectingByState(Context context) 判断当前网络是否正在断开
      static boolean isSuspendedByState(Context context) 判断当前网络是否已经暂停
      static int getWifiState(Context context) 获取Wifi的状态,需要ACCESS_WIFI_STATE权限
      static boolean isWifiOpen(Context context) 判断Wifi是否打开,需要ACCESS_WIFI_STATE权限
      static boolean setWifi(Context context, boolean enable) 设置Wifi,需要CHANGE_WIFI_STATE权限
      static String getIpAddress() 获取本机IP地址
      static WifiInfo getWifiConnectionInfo(Context context) 获取wifi连接信息
      static String getProxy(Context context) 获得Proxy地址
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • openNetSetting

         static void openNetSetting(Activity activity)

        打开网络设置界面

        Parameters:
        activity - Activity
      • getCurrentNetworkState

         static NetworkInfo.State getCurrentNetworkState(Context context)

        获取当前网络的状态

        Parameters:
        context - 上下文
      • isConnectedByState

         static boolean isConnectedByState(Context context)

        判断当前网络是否已经连接

        Parameters:
        context - 上下文
      • isConnectingByState

         static boolean isConnectingByState(Context context)

        判断当前网络是否正在连接

        Parameters:
        context - 上下文
      • isDisconnectedByState

         static boolean isDisconnectedByState(Context context)

        判断当前网络是否已经断开

        Parameters:
        context - 上下文
      • isDisconnectingByState

         static boolean isDisconnectingByState(Context context)

        判断当前网络是否正在断开

        Parameters:
        context - 上下文
      • isSuspendedByState

         static boolean isSuspendedByState(Context context)

        判断当前网络是否已经暂停

        Parameters:
        context - 上下文
      • getWifiState

         static int getWifiState(Context context)

        获取Wifi的状态,需要ACCESS_WIFI_STATE权限

        Parameters:
        context - 上下文
      • isWifiOpen

         static boolean isWifiOpen(Context context)

        判断Wifi是否打开,需要ACCESS_WIFI_STATE权限

        Parameters:
        context - 上下文
      • setWifi

         static boolean setWifi(Context context, boolean enable)

        设置Wifi,需要CHANGE_WIFI_STATE权限

        Parameters:
        context - 上下文
        enable - wifi状态
      • getProxy

         static String getProxy(Context context)

        获得Proxy地址

        Parameters:
        context - 上下文