-
-
Save KatieBarnett/12e07bb59fae810b850b4f741fbdcf4a to your computer and use it in GitHub Desktop.
Downloading an image to a file in a Coroutine Worker - Part 2
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 suspend fun downloadImage(...): String { | |
| ... | |
| // Get the path of the loaded image from DiskCache. | |
| val path = context.imageLoader.diskCache?.openSnapshot(url)?.use { snapshot -> | |
| val imageFile = snapshot.data.toFile() | |
| // Use the FileProvider to create a content URI | |
| val contentUri = getUriForFile( | |
| context, | |
| "${applicationContext.packageName}.provider", | |
| imageFile, | |
| ) | |
| // return the path | |
| contentUri.toString() | |
| } | |
| return requireNotNull(path) { | |
| "Couldn't find cached file" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment