Skip to content

Instantly share code, notes, and snippets.

@chayanforyou
Created August 27, 2022 17:19
Show Gist options
  • Save chayanforyou/28e150923ee2caaf14b6d0d8a4807798 to your computer and use it in GitHub Desktop.
Save chayanforyou/28e150923ee2caaf14b6d0d8a4807798 to your computer and use it in GitHub Desktop.
Simplify Android Storage Access Framework for file management across API levels.

Simplify Android Storage Access Framework for file management across API levels. https://github.com/anggrayudi/SimpleStorage

fun saveFile(bitmap: Bitmap, context: Context) {
    val fileDesc = FileDescription("test_image.jpg", "MyFolder", "image/*")
    val image = DocumentFileCompat.createPictureWithMediaStoreFallback(context, fileDesc)

    val fos = image?.openOutputStream(context)
    fos?.use {
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, it)
    }
    fos?.close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment