Skip to content

Commit

Permalink
fix: should use methods supported in API 16
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Oct 27, 2023
1 parent eb74971 commit 8bcbb5b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions core/src/main/java/com/amplitude/core/utilities/HttpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import java.io.OutputStream
import java.net.HttpURLConnection
import java.net.MalformedURLException
import java.net.URL
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.TimeZone

internal class HttpClient(
private val configuration: Configuration
Expand Down Expand Up @@ -85,7 +86,10 @@ internal class HttpClient(
}

internal fun getClientUploadTime(): String {
return ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT)
val currentTimeMillis = System.currentTimeMillis()
val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
sdf.timeZone = TimeZone.getTimeZone("UTC")
return sdf.format(Date(currentTimeMillis))
}

internal fun getMindIdLength(): Int? {
Expand Down Expand Up @@ -144,9 +148,9 @@ abstract class Connection(

private fun getBodyStr(): String {
if (minIdLength == null) {
return "{\"api_key\":\"$apiKey\",\"events\":$events}"
return "{\"api_key\":\"$apiKey\",\"client_upload_time\":\"$clientUploadTime\",\"events\":$events}"
}
return "{\"api_key\":\"$apiKey\",\"events\":$events,\"options\":{\"min_id_length\":$minIdLength}}"
return "{\"api_key\":\"$apiKey\",\"client_upload_time\":$clientUploadTime,\"events\":$events,\"options\":{\"min_id_length\":$minIdLength}}"
}
}

Expand Down

0 comments on commit 8bcbb5b

Please sign in to comment.