Download Large File with MediaStore Android 10

放肆的年华 提交于 2020-07-09 03:14:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!