2017-07-28 38 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

通過這種方式,我們可以正常地做,但我的網址是用密碼保護的,所以如何做到這一點這個問題。 –