My onActivityResult
is not working because getBitmap
is deprecated, any alternative codes to achieve this?
here are the codes that needs to
Have you tried this?
val bitmap = ImageDecoder.createSource(contentResolver, uri)
It was evident that the getBitmap
API doesn't work with the latest Android SDK - 29. So, this worked for me
Uri contentURI = data.getData();
try {
imageView.setImageURI(contentURI);
} catch (Exception e) {
e.printStackTrace();
}
Please let me know if this doesn't work for any of you, shall other options!
You can use this code for creating bitmap
Bitmap bitmap;
if (Build.VERSION.SDK_INT >= 29) {
ImageDecoder.Source source = ImageDecoder.createSource(getApplicationContext().getContentResolver(), imageUri);
try {
bitmap = ImageDecoder.decodeBitmap(source);
} catch (IOException e) {
e.printStackTrace();
}
} else {
try {
bitmap = MediaStore.Images.Media.getBitmap(getApplicationContext().getContentResolver(), imageUri);
} catch (IOException e) {
e.printStackTrace();
}
}