Class DefaultConnectivityCheck

  • All Implemented Interfaces:
    ConnectivityCheck

    public class DefaultConnectivityCheck
    extends Object
    implements ConnectivityCheck
    The default implementation of the connectivity checker. This implementation uses the systems ConnectivityManager to resolve the current NetworkInfo and then uses NetworkInfo.isConnected() to check for connectivity.

    If you specify a lookup host name, a name lookup will be done to verify connectivity if the ConnectivityManager reports that the device is connected. We do this because there seems to be a slight delay and inaccuracy where the ConnectivityManager reports that we have connectivity, but that is actually not the case. To verify connectivity, we do a host name lookup for the given host to verify connectivity. This is an optional step and will be omitted if no lookup host name is specified.

    Since:
    3.1.2
    • Constructor Detail

      • DefaultConnectivityCheck

        public DefaultConnectivityCheck​(@NonNull
                                        Context context)
        Create a new instance of the connectivity checker to "google.com" lookup host
        Parameters:
        context - The context
      • DefaultConnectivityCheck

        public DefaultConnectivityCheck​(@NonNull
                                        Context context,
                                        @Nullable
                                        String lookupHost)
        Create a new instance of the connectivity checker.
        Parameters:
        context - The context
        lookupHost - The lookup host. If this is specified, the connectivity check will try to resolve the IP address of the given host name to verify connectivity.
    • Method Detail

      • isConnected

        public boolean isConnected()
        Description copied from interface: ConnectivityCheck
        Returns true if an internet connection is available
        Specified by:
        isConnected in interface ConnectivityCheck
        Returns:
        True if an internet connection is available