Package com.castlabs.android.network
Class DefaultConnectivityCheck
java.lang.Object
com.castlabs.android.network.DefaultConnectivityCheck
- All Implemented Interfaces:
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 Summary
ConstructorDescriptionDefaultConnectivityCheck
(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
Modifier and TypeMethodDescriptionboolean
Returns true if an internet connection is available
-
Constructor Details
-
DefaultConnectivityCheck
Create a new instance of the connectivity checker to "google.com" lookup host- Parameters:
context
- The context
-
DefaultConnectivityCheck
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 Details
-
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
-