How to set MediaStore openOutputStream offset in Long?

你。 提交于 2020-02-05 04:01:07

问题


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

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