# SntpClient

# SntpClient

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/exoplayer/util/SntpClient "View this page in Java")

<br />

```
@UnstableApi
class SntpClient
```

<br />

*** ** * ** ***

Static utility to retrieve the device time offset using SNTP.

Based on the[Android framework SntpClient](https://cs.android.com/android/_/android/platform/frameworks/base/+/ea1b85a5eb6e9dcddf7abc6c74479bfadf9017c7:core/java/android/net/SntpClient.java).

## Summary

|                                                                                                                                                                                                   ### Nested types                                                                                                                                                                                                   |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `interface `[SntpClient.InitializationCallback](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient.InitializationCallback) Callback for calls to[initialize](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#initialize(androidx.media3.exoplayer.upstream.Loader,androidx.media3.exoplayer.util.SntpClient.InitializationCallback)). |

|                                        ### Constants                                         |
|----------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | [DEFAULT_NTP_HOST](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#DEFAULT_NTP_HOST())` = "time.android.com"` The default NTP host address used to retrieve[getElapsedRealtimeOffsetMs](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#getElapsedRealtimeOffsetMs()). |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | [DEFAULT_TIMEOUT_MS](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#DEFAULT_TIMEOUT_MS())` = 1000` The default maximum time, in milliseconds, to wait for the SNTP request to complete.                                                                                                                        |

|                                    ### Public functions                                     |
|---------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [initialize](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#initialize(androidx.media3.exoplayer.upstream.Loader,androidx.media3.exoplayer.util.SntpClient.InitializationCallback))`(loader: `[Loader](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader)`?, callback: `[SntpClient.InitializationCallback](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient.InitializationCallback)`?)` Starts loading the device time offset. |

|                                       ### Public properties                                        |
|----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java-static `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)        | `@`[GuardedBy](https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy)`(value = "valueLock")` [elapsedRealtimeOffsetMs](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#elapsedRealtimeOffsetMs())         |
| `java-static `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)  | `@`[GuardedBy](https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy)`(value = "valueLock")` [isInitialized](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#isInitialized())                             |
| `java-static `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)        | `@`[GuardedBy](https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy)`(value = "valueLock")` [maxElapsedTimeUntilUpdateMs](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#maxElapsedTimeUntilUpdateMs()) |
| `java-static `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!` | `@`[GuardedBy](https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy)`(value = "valueLock")` [ntpHost](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#ntpHost())                                         |
| `java-static `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | `@`[GuardedBy](https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy)`(value = "valueLock")` [timeoutMs](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#timeoutMs())                                     |

## Constants

### DEFAULT_NTP_HOST

```
const val DEFAULT_NTP_HOST = "time.android.com": String!
```

The default NTP host address used to retrieve[getElapsedRealtimeOffsetMs](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient#getElapsedRealtimeOffsetMs()).  

### DEFAULT_TIMEOUT_MS

```
const val DEFAULT_TIMEOUT_MS = 1000: Int
```

The default maximum time, in milliseconds, to wait for the SNTP request to complete.  

## Public functions

### initialize

```
java-static fun initialize(loader: Loader?, callback: SntpClient.InitializationCallback?): Unit
```

Starts loading the device time offset.  

|                                                                             Parameters                                                                              |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `loader: `[Loader](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader)`?`                                                     | A[Loader](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/upstream/Loader)to use for loading the time offset, or null to create a new one.                                                                    |
| `callback: `[SntpClient.InitializationCallback](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient.InitializationCallback)`?` | An optional[InitializationCallback](https://developer.android.com/reference/kotlin/androidx/media3/exoplayer/util/SntpClient.InitializationCallback)to be notified when the time offset has been initialized or initialization failed. |

## Public properties

### elapsedRealtimeOffsetMs

```
@GuardedBy(value = "valueLock")
java-static val elapsedRealtimeOffsetMs: Long
```  

### isInitialized

```
@GuardedBy(value = "valueLock")
java-static val isInitialized: Boolean
```  

### maxElapsedTimeUntilUpdateMs

```
@GuardedBy(value = "valueLock")
java-static var maxElapsedTimeUntilUpdateMs: Long
```  

### ntpHost

```
@GuardedBy(value = "valueLock")
java-static var ntpHost: String!
```  

### timeoutMs

```
@GuardedBy(value = "valueLock")
java-static var timeoutMs: Int
```