Object NetworkUtils
-
- All Implemented Interfaces:
public class NetworkUtilsUtility class for checking network connectivity status.
This utility provides a unified way to check network availability across different Android API levels. It handles both modern (API 23+) and legacy network checking approaches to ensure compatibility with a wide range of devices.
- Since:
4.3.2
-
-
Field Summary
Fields Modifier and Type Field Description public final static NetworkUtilsINSTANCE
-
Method Summary
Modifier and Type Method Description final BooleanisNetworkAvailable(Context context)Checks if a network connection is currently available and validated. final UnitclearCache()Force clear the network state cache. -
-
Method Detail
-
isNetworkAvailable
final Boolean isNetworkAvailable(Context context)
Checks if a network connection is currently available and validated.
This method performs a comprehensive network availability check that:
On API 23+: Verifies both internet capability and network validation
On older APIs: Falls back to checking connected state of active network
The validation check ensures that the network can actually reach the internet, not just that it's connected to a router or access point.
- Parameters:
context- The application context used to access system services- Returns:
trueif a validated network connection is available,falseotherwise
-
clearCache
final Unit clearCache()
Force clear the network state cache. Useful when you need an immediate accurate network check.
-
-
-
-