2017-07-28 79 views
0

我得到一个图像的URL与密码保护。我知道如何做与认证,但我想这样做与毕加索。 任何人都可以告诉我,如何将密码保护的图像加载到带有毕加索图像加载程序库的imageview。用picasso加载密码保护的图像到imageview图像加载器库在android

下面是代码做身份验证:

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; 

     } 
+0

你如何做与认证?你能告诉我们吗?你如何将密码传递给url? – SripadRaj

回答

0

我相信这是你要找的内容。这篇文章说可以使用Okhttp完成。

How to add Basic Authentication in Picasso 2.5.2 with OkHttp 3.2.0

好运。 :)

编辑

您可以将图像设置为类似下面的图像显示。

Picasso.with(context).load("YOUR IMAGE URL HERE").into(imageView); 
+0

谢谢你的回答,但是你能否告诉我最终如何将图像设置为图像视图? –

+0

@Akshaykumar你有图像的网址?检查我更新的答案。 – SripadRaj

+0

通过这种方式,我们可以正常地做,但我的网址是用密码保护的,所以如何做到这一点这个问题。 –