Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error on loading image from https url using Picasso library

In my application I'm trying to load image from an https URL using Picasso library.I am unable to load image into ImageView. I am using Picasso 2.5.2 and I am setting the image as follows:

  Picasso.with(mContext)
            .load(GlobalVariable.movieDetails.get(0).getVideo_cover_image())
            .placeholder(R.drawable.animation_placeholder)
            .error(R.drawable.animation_placeholder)
            .into(iv_image);
like image 715
Rishikesh Rahi Avatar asked Mar 11 '26 23:03

Rishikesh Rahi


1 Answers

Try this

if (TextUtils.isEmpty(imageUrl) && !isValidUrl(imageUrl)) {
                iv_image.setImageResource(R.drawable.default);

            } else {
                Picasso.with(context)
                        .load(imageUrl)
                        .resize(70, 70)//if you want resize image
                        .centerInside()
                        .into(iv_image, new com.squareup.picasso.Callback() {
                            @Override
                            public void onSuccess() {

                            }

                            @Override
                            public void onError() {
                                iv_image.setImageResource(R.drawable.default);
                            }
                        });
            }

validate URL

 public static boolean isValidUrl(String string) {

    boolean b = Patterns.WEB_URL.matcher(string).matches();
    return b;
}
like image 174
Adil Avatar answered Mar 13 '26 13:03

Adil