3

I am trying to download a file to download the directory in Android 10 and above. I did as following.

val resolver = contentResolver
val contentValues = ContentValues().apply {
    put(MediaStore.MediaColumns.DISPLAY_NAME, "CuteKitten001")
    put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg")
    put(MediaStore.MediaColumns.RELATIVE_PATH, "Download/PerracoLabs")
}
val uri = resolver.insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, contentValues)
val outputStream: OutputStream? = if (uri == null) null else resolver.openOutputStream(uri)


hiper.get("https://httpbin.org/image", isStream = true)
    .ifException { e ->
            Log.d(TAG, "Exception: ${e?.message}")
        }
    .ifFailed { response ->
        Log.d(TAG, "Failed")
    }
    .ifStream { buffer, byteSize ->
        if (buffer == null) {
            outputStream?.flush()
            outputStream?.close()
            Log.d(TAG, "Done.")
        } else {
            outputStream?.write(buffer, 0, byteSize)
        }
    }
    .finally { response ->
        Log.d(TAG, response.text.toString())
    }

outputStream?.write(buffer, 0, byteSize) in this line it take an integer as an offset, but if I want to move the offset over 2 gigabytes I need a Long.

David
  • 31
  • 4
  • Perhaps you could switch to a different HTTP client API. OkHttp, for example, [does not require you to mess with byte sizes](https://stackoverflow.com/a/29012988/115145). Note that you may have filesystem issues with files of that size. – CommonsWare Jan 30 '20 at 17:15
  • Why are you starting a new thread? https://stackoverflow.com/questions/59986065/how-to-set-mediastore-openoutputstream-offset-in-long?noredirect=1#comment106094563_59986065. Nothing learned from the comments? – blackapps Jan 30 '20 at 21:21

0 Answers0