我正在尝试下载一个文件来下载Android 10及以上版本的目录。我做了如下。
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)
在这一行中,它采用一个整数作为偏移量,但如果我想将偏移量移动超过 2 GB,我需要一个 Long。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)