NetworkConnectivityChecker

class NetworkConnectivityChecker(context: Context)

Helper class to check the network connectivity.

Parameters

context

to get the a system-level service class ConnectivityManager.

Note: System services obtained via this API may be closely associated with the Context in which they are obtained from. In general, do not share the service objects between various different contexts (Activities, Applications, Services, Providers, etc.)

Constructors

Link copied to clipboard
fun NetworkConnectivityChecker(context: Context)

Types

Link copied to clipboard
fun interface OmhOnLostConnection

Inner interface to handle when the connection is lost.

Functions

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.ACCESS_NETWORK_STATE"])
fun isNetworkAvailable(): Boolean

Checks if there is internet connection.

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.ACCESS_NETWORK_STATE"])
fun startListeningForConnectivityChanges(onLostConnection: NetworkConnectivityChecker.OmhOnLostConnection)

Register callbacks to receive notifications when different network states change.

Link copied to clipboard

Unregisters the all registered callbacks if possible.