Package com.castlabs.android.network
Class DefaultConnectivityCheck
- java.lang.Object
-
- com.castlabs.android.network.DefaultConnectivityCheck
-
- All Implemented Interfaces:
ConnectivityCheck
public class DefaultConnectivityCheck extends Object implements ConnectivityCheck
The default implementation of the connectivity checker. This implementation uses the systemsConnectivityManager
to resolve the currentNetworkInfo
and then usesNetworkInfo.isConnected()
to check for connectivity. If you specify a lookup host name, a name lookup will be done to verify connectivity if theConnectivityManager
reports that the device is connected. We do this because there seems to be a slight delay and inaccuracy where theConnectivityManager
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 Summary
Constructors Constructor Description DefaultConnectivityCheck(Context context)
Create a new instance of the connectivity checker to "google.com" lookup hostDefaultConnectivityCheck(Context context, String lookupHost)
Create a new instance of the connectivity checker.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isConnected()
Returns true if an internet connection is available
-
-
-
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 contextlookupHost
- 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 interfaceConnectivityCheck
- Returns:
- True if an internet connection is available
-
-