问题
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())
}
In outputStream?.write(buffer, 0, byteSize)
line the offset takes an integer, but I want to use a Long
so that I can download files larger than 2GB
.
来源:https://stackoverflow.com/questions/59986065/how-to-set-mediastore-openoutputstream-offset-in-long