Package android.net

Class ConnectivityManager

  • Direct Known Subclasses:
    PollerConnectivityManager

    public class ConnectivityManager
    extends Object
    Class that answers queries about the state of network connectivity. It also notifies applications when network connectivity changes. Get an instance is dependent on the underlying system.
    • Constructor Detail

      • ConnectivityManager

        protected ConnectivityManager()
    • Method Detail

      • getActiveNetworkInfo

        @Nullable
        public NetworkInfo getActiveNetworkInfo()
        Returns details about the currently active default data network. When connected, this network is the default route for outgoing connections. You should always check NetworkInfo.isConnected() before initiating network traffic. This may return null when there is no default network.
        Returns:
        a NetworkInfo object for the current default network or null if no network default network is currently active
      • getActiveNetwork

        @Nullable
        public Network getActiveNetwork()
        Returns a Network object corresponding to the currently active default data network. In the event that the current active default data network disconnects, the returned Network object will no longer be usable. This will return null when there is no default network.
        Returns:
        a Network object for the current default network or null if no default network is currently active
      • getAllNetworks

        public Network[] getAllNetworks()
        Returns an array of all Network currently tracked by the framework.
        Returns:
        an array of Network objects.
      • getNetworkInfo

        @Nullable
        public NetworkInfo getNetworkInfo​(Network network)
        Returns connection status information about a particular Network.
        Parameters:
        network - Network specifying which network in which you're interested.
        Returns:
        a NetworkInfo object for the requested network or null if the Network is not valid.
      • setActiveNetwork

        protected void setActiveNetwork​(Network network)
        Sets the active network.
        Parameters:
        network - the network to set.
      • notifyNetworkCallbacks

        protected void notifyNetworkCallbacks​(Network network,
                                              boolean available)
        Notifies a network availability change.
        Parameters:
        network - the network.
        available - true if the network is available.
      • notifyNetworkCallbacks

        protected void notifyNetworkCallbacks​(Network network,
                                              NetworkCapabilities capabilities)
        Notifies a network capability change.
        Parameters:
        network - the network.
        capabilities - the network capabilities.
      • setAvailable

        protected void setAvailable​(boolean available,
                                    @Nullable
                                    Network network,
                                    NetworkInfo networkInfo)
        Sets the network availability.
        Parameters:
        available - true if available.
        network - the network.
        networkInfo - the network info.
      • doNotifyCapabilitiesChange

        protected void doNotifyCapabilitiesChange​(Network network,
                                                  NetworkCapabilities capabilities,
                                                  ConnectivityManager.NetworkCallback[] networkCallBacks)
        Notify the callback of a capabilities change.
        Parameters:
        network - the network.
        capabilities - the capabilities.
        networkCallBacks - the callback to call.
      • doNotifyAvailabilityChange

        protected void doNotifyAvailabilityChange​(Network network,
                                                  boolean available,
                                                  ConnectivityManager.NetworkCallback[] networkCallbacks)
        Notify the networkCallbacks about an availability change.
        Parameters:
        network - the network.
        available - the availability.
        networkCallbacks - the callback to call.