Last active
July 21, 2020 13:01
-
-
Save pratclot/2e45f6a37e1f747171d28f0a97edbb2f to your computer and use it in GitHub Desktop.
Write data to a file on Android via MediaStore API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun saveFileToMediaStorage(bmp: Bitmap) { | |
val resolver = applicationContext.contentResolver | |
val contentValues = ContentValues().apply { | |
put(MediaStore.MediaColumns.DISPLAY_NAME, "photo.bmp") | |
put(MediaStore.MediaColumns.MIME_TYPE, "image/bmp") | |
put(MediaStore.MediaColumns.RELATIVE_PATH, "Pictures/") | |
} | |
val uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues) | |
uri?.let { | |
resolver.openOutputStream(uri).use { | |
bmp.compress(Bitmap.CompressFormat.JPEG, quality, it) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment