Skip to content

Instantly share code, notes, and snippets.

@oliverspryn
Created November 12, 2021 13:36
Show Gist options
  • Select an option

  • Save oliverspryn/a501ec1853bcaccf0b2983a56336226a to your computer and use it in GitHub Desktop.

Select an option

Save oliverspryn/a501ec1853bcaccf0b2983a56336226a to your computer and use it in GitHub Desktop.
The image decoder with proper support for testing API-dependent code
class ImageController @Inject constructor(
@Named(BuildModule.sdkVersion) private val sdkVersion
) {
fun decodeAndProcessImage(uri: Uri) {
val bitmap = if (sdkVersion < Build.VERSION_CODES.P) {
MediaStore.Images.Media.getBitmap(contentResolver, uri)
} else {
val source = ImageDecoder.createSource(contentResolver, uri)
ImageDecoder.decodeBitmap(source)
}
// Do something with the Bitmap
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment