Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7184.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash on previewing images to upload on Android Pie.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ object ImageUtils {
fun getBitmap(context: Context, uri: Uri): Bitmap? {
return try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.decodeBitmap(ImageDecoder.createSource(context.contentResolver, uri))
val source = ImageDecoder.createSource(context.contentResolver, uri)
val listener = ImageDecoder.OnHeaderDecodedListener { decoder, _, _ ->
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P) {
// Allocating hardware bitmap may cause a crash on framework versions prior to Android Q
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE
}
}

ImageDecoder.decodeBitmap(source, listener)
} else {
context.contentResolver.openInputStream(uri)?.use { inputStream ->
BitmapFactory.decodeStream(inputStream)
Expand Down