# NetworkTypeObserver

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/NetworkTypeObserver.java+class:androidx.media3.common.util.NetworkTypeObserver)

*** ** * ** ***


```
@UnstableApi
class NetworkTypeObserver
```

<br />

*** ** * ** ***

Observer for network type changes.

`https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#register(androidx.media3.common.util.NetworkTypeObserver.Listener)` listeners are informed at registration and whenever the network type changes.

The current network type can also be `https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#getNetworkType()` without registration.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver.Listener` A listener for network type changes. |

| ### Public functions |
|---|---|
| `synchronized java-static https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver!` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#getInstance(android.content.Context)(context: https://developer.android.com/reference/android/content/Context.html!)` Returns a network type observer instance. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://checkerframework.org/api/com/google/errorprone/annotations/InlineMe.html(replacement = "this.register(listener, new Handler(Looper.getMainLooper())::post)", imports = [""android.os.Handler"", ""android.os.Looper""]) [register](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#register(androidx.media3.common.util.NetworkTypeObserver.Listener))(listener: https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver.Listener!)` **This function is deprecated.** Use `https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#register(androidx.media3.common.util.NetworkTypeObserver.Listener,java.util.concurrent.Executor)` instead. <br /> |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#register(androidx.media3.common.util.NetworkTypeObserver.Listener,java.util.concurrent.Executor)(listener: https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver.Listener!, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html!)` Registers a listener. |
| `synchronized java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/VisibleForTesting https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#resetForTests()()` Resets the network type observer for tests. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy(value = "lock") @https://developer.android.com/reference/kotlin/androidx/media3/common/C.NetworkType https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#networkType()` |

## Public functions

### getInstance

```
synchronized java-static fun getInstance(context: Context!): NetworkTypeObserver!
```

Returns a network type observer instance.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html!` | A `https://developer.android.com/reference/android/content/Context.html`. |

### register

```
@InlineMe(replacement = "this.register(listener, new Handler(Looper.getMainLooper())::post)", imports = [""android.os.Handler"", ""android.os.Looper""])
fun [register](https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#register(androidx.media3.common.util.NetworkTypeObserver.Listener))(listener: NetworkTypeObserver.Listener!): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
>
> Use `https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver#register(androidx.media3.common.util.NetworkTypeObserver.Listener,java.util.concurrent.Executor)` instead.

### register

```
fun register(listener: NetworkTypeObserver.Listener!, executor: Executor!): Unit
```

Registers a listener.

The current network type will be reported to the listener after registration.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver.Listener!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/util/NetworkTypeObserver.Listener`. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html!` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` to call the `listener` on. |

### resetForTests

```
@VisibleForTesting
synchronized java-static fun resetForTests(): Unit
```

Resets the network type observer for tests.

## Public properties

### networkType

```
@GuardedBy(value = "lock")
@C.NetworkType
val networkType: Int
```