Package 

Class NetworkConnectivityChecker


  • 
    public final class NetworkConnectivityChecker
    
                        

    Utility for checking network connectivity state.

    This class provides efficient connectivity checks by caching the network state and updating it via system callbacks, avoiding expensive system calls on each check.

    val checker = NetworkConnectivityChecker(context)
    
    if (checker.isConnected()) {
        // Proceed with network operation
    }

    All methods are thread-safe. The connectivity state is tracked using atomic operations.

    • Method Summary

      Modifier and Type Method Description
      final Boolean isConnected() Check if the device currently has network connectivity.
      final Boolean checkConnectivityNow() Perform a synchronous connectivity check.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NetworkConnectivityChecker

        NetworkConnectivityChecker(Context context)
    • Method Detail

      • isConnected

         final Boolean isConnected()

        Check if the device currently has network connectivity.

        This method checks for actual internet connectivity, not just network availability. A device might be connected to WiFi but have no internet access (captive portal, etc.).

      • checkConnectivityNow

         final Boolean checkConnectivityNow()

        Perform a synchronous connectivity check.

        This method queries the system directly rather than using cached state. Use isConnected for most cases as it's more efficient.