簡體   English   中英

使用Android中的Picasso圖像加載器庫將受密碼保護的圖像加載到imageview

[英]Load password protected image to imageview with Picasso Image loader Library in android

我收到一個受密碼保護的圖像網址。我知道如何使用Authenticator進行此操作,但我想使用Picasso進行此操作。 誰能告訴我如何使用Picasso Image loader Library將受密碼保護的圖像加載到imageview。

以下是與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;

        }

我相信這就是您要尋找的。 帖子說可以使用Okhttp完成。

如何使用OkHttp 3.2.0在Picasso 2.5.2中添加基本身份驗證

祝好運。 :)

編輯

您可以將圖像設置為如下所示的圖像視圖。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM