Skip to content

Commit

Permalink
NetworkObserver SDK checks inconsistency resolved (#996)
Browse files Browse the repository at this point in the history
Check for API to be N+ when unregistering network observer
  • Loading branch information
maharshpatel247 authored Jun 8, 2023
1 parent ab6efa3 commit a8d2924
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ internal class NetworkObserver(private val context: Context) {

/** Stop observing network changes and cleanup */
fun destroy() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Min API for `unregisterNetworkCallback` is L, but we use `registerDefaultNetworkCallback` only for N and above.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val callback = networkCallback ?: return
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
connectivityManager.unregisterNetworkCallback(callback)
Expand Down

0 comments on commit a8d2924

Please sign in to comment.