0

i am getting an image url which is protected with password.I know how to do it with the Authenticator but i want to do this with Picasso. Can anyone please tell me that how to load password protected images to a imageview with Picasso Image loader Library.

Below is the code to do with Authenticator:

private Bitmap download_Image(String url) {

            Bitmap bmp = null;
            try {
                URL ulrn = new URL(url);
                Authenticator.setDefault(new Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(imagePassword, "mypass".toCharArray());
                    }
                });
                HttpURLConnection con = (HttpURLConnection) ulrn.openConnection();
                InputStream is = con.getInputStream();
                bmp = BitmapFactory.decodeStream(is);
                if (null != bmp)
                    return bmp;

            } catch (Exception e) {
                e.printStackTrace();
            }
            return bmp;

        }
Akshay kumar
  • 102
  • 8
  • How do you do it with authenticator? could you show us please? how do you pass the password to the url? – SripadRaj Jul 28 '17 at 08:42

1 Answers1

0

I believe this is what you're looking for. The post says it could be done using Okhttp.

How to add Basic Authentication in Picasso 2.5.2 with OkHttp 3.2.0

Good luck. :)

Edit

You can set the image to your image view like below.

Picasso.with(context).load("YOUR IMAGE URL HERE").into(imageView);
SripadRaj
  • 1,687
  • 2
  • 22
  • 33