Reputation: 2707
I am using File picker to get image as File and then I want to load it into ImageView with Glide.
I am trying to use this code, but it fails to load image into image view.
Glide.with(getApplicationContext())
.load(Uri.fromFile(imageFile))
.error(R.drawable.ic_person_gray)
.listener(new RequestListener<Uri, GlideDrawable>() {
@Override public boolean onException(
Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource
) {
Timber.d(e.getMessage());
return false;
}
@Override public boolean onResourceReady(
GlideDrawable resource,
Uri model,
Target<GlideDrawable> target,
boolean isFromMemoryCache,
boolean isFirstResource
) {
editProfilePresenter.uploadProfilePicture(imageFile);
return false;
}
})
.into(ivAvatar);
When I do debug, it never reaches debug points inside onException or onResourceReady.
How I can fix this?
Upvotes: 1
Views: 1070
Reputation: 754
You don't need an Uri there, you can just get the path of your file, and your listener will look like this My ex:
Glide.with(context).load(yourFile.getAbsolutePath()).centerCrop().listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
spinKitView.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
spinKitView.setVisibility(View.GONE);
return false;
}
}).into(ivAvatar);
SpinkitView is just a view that shows a loading animation (in case takes time to load the picture)
Upvotes: 0