While using the picasso library to get a contact avatar from a uri I get the following error:
FileNotFoundException content://com.android.contacts/contacts/141/photo
A similar implementation in Java with the same uri works fine. In Java I'm loading the uri directly with imageview field but in jetpack I'm using Target.
var image by remember { mutableStateOf<ImageBitmap?>(null) }
val uri = viewModel.getAvatarUri().get(neme)?.get()
var drawable by remember { mutableStateOf<Drawable?>(null) }
DisposableEffect(uri) {
val picasso = Picasso.get()
val target = object : Target {
override fun onPrepareLoad(placeHolderDrawable: Drawable?) {
drawable = placeHolderDrawable
}
override fun onBitmapFailed(e: Exception?, errorDrawable: Drawable?) {
println(e) //error
drawable = errorDrawable
}
override fun onBitmapLoaded(bitmap: Bitmap?, from: Picasso.LoadedFrom?) {
image = bitmap?.asImageBitmap()
}
}
picasso
.load(uri)
.placeholder(R.drawable.person)
.into(target)
onDispose {
image = null
drawable = null
picasso.cancelRequest(target)
}
}
Image(
image!!, contentDescription = "Avatar",
modifier = Modifier
.size(48.dp)
.background(Color.Gray, CircleShape)
)
"Nobody works on Picasso. If you want something in the next N years definitely use Coil. Or Glide. Or whatever. They're all fine." - Jake Wharton
https://github.com/square/picasso/issues/2203