Created
September 7, 2025 10:48
-
-
Save root-ansh/473ff1cdf8a329d6050143cfcc7fb823 to your computer and use it in GitHub Desktop.
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
| @Throws | |
| suspend fun Context.saveFileToUserSelectedPath(uri: Uri, sourceFile: File): Uri { | |
| return withContext(Dispatchers.IO) { | |
| contentResolver.openOutputStream(uri)?.use { outputStream -> | |
| sourceFile.inputStream().use { inputStream -> | |
| inputStream.copyTo(outputStream) | |
| } | |
| } | |
| uri | |
| } | |
| } | |
| suspend fun Context.saveBitmapToUserSelectedPath(uri: Uri, bitmap: Bitmap): Uri { | |
| return withContext(Dispatchers.IO){ | |
| contentResolver.openOutputStream(uri)?.use { outputStream -> | |
| bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream) | |
| outputStream.flush() | |
| } | |
| uri | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment