问题
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.
来源:https://stackoverflow.com/questions/59991109/download-large-file-with-mediastore-android-10