Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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.Q) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case, it could be replaced by

Suggested change
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P) {

But I understand that it's more logic to keep the code like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, I assumed there might be something in between, like there is with O_MR1 but there indeed isn't.

// Allocating hardware bitmap may cause a crash on framework versions prior to Android Q
decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a compilation warning, it could be replaced by

Suggested change
decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE)
decoder.allocator = ImageDecoder.ALLOCATOR_SOFTWARE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}

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