user9319961
user9319961

Reputation: 11

Image not loading through URL in ImageView using Picasso android

I am using the Picasso library to set the image from URL. This URL is working in other programming language but not in Android.

Picasso.with(context).load(product_modal.getImage()).placeholder(R.drawable.ic_no_image).into(holder.iv_thumbnail_filled);

Upvotes: 0

Views: 3330

Answers (3)

voodoo98
voodoo98

Reputation: 175

If you have HTTP 504 error, have a try: Uninstalling the app and installing it again!

Info from here.

Upvotes: 0

Faysal Ahmed
Faysal Ahmed

Reputation: 7669

Finally, I found the actual problem that you have faced. Replace https to http in your URL. Because your site does not have SSL.

Just created a method for loading image

    private void loadImage(final ImageView imageView, final String imageUrl){
    Picasso.get()
            .load(imageUrl)
            .placeholder(R.drawable.image_white)
            .into(imageView , new Callback() {
                @Override
                public void onSuccess() { 
                }

                @Override
                public void onError(Exception e) {
                     String updatedImageUrl;
                    if (imageUrl.contains("https")){
                         updatedImageUrl = imageUrl.replace("https", "http");
                    }else{
                         updatedImageUrl = imageUrl.replace("http", "https");
                    }
                    loadImage(imageView, updatedImageUrl);
                }
            });
}

You just need to provide an imageView and the image URL. For the first time if image not loaded then its try to replace https to http and then try load the image.

Using the method by using this:

loadImage(holder.iv_thumbnail_filled, product_modal.getImage());

And make sure you have Internet Access Permission on AndroidMenifest.xml

<uses-permission android:name="android.permission.INTERNET"/>

Hope this will solve your problem.

Upvotes: 1

Zain
Zain

Reputation: 40810

According to Picasso library, they've changed the way of loading images

Please use the below to load image

Picasso.get().load(product_modal.getImage()).placeholder(R.drawable.ic_no_image).into(holder.iv_thumbnail_filled);

You can check this question for more info.

Upvotes: 0

Related Questions