Package 

Class NetworkConnectivityChecker


  • 
    public 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.

    • Constructor Detail

      • NetworkConnectivityChecker

        NetworkConnectivityChecker(Context context)
    • Method Detail

      • isConnected

         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.