Skip to content

Commit

Permalink
Registering for default network (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanicMa authored Dec 2, 2024
1 parent 51627c7 commit 6c00d0e
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ internal class AndroidConnectivityProvider(
?: return flowOf(Connectivity.Status.Disconnected)

return callbackFlow {
val networkRequest = NetworkRequest.Builder().build()

val networkCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
val capabilities = manager.getNetworkCapabilities(network)
Expand All @@ -51,7 +49,12 @@ internal class AndroidConnectivityProvider(
}

try {
manager.registerNetworkCallback(networkRequest, networkCallback)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
manager.registerDefaultNetworkCallback(networkCallback)
} else {
val networkRequest = NetworkRequest.Builder().build()
manager.registerNetworkCallback(networkRequest, networkCallback)
}

val initialStatus = manager.initialStatus()
trySend(initialStatus)
Expand Down

0 comments on commit 6c00d0e

Please sign in to comment.