[英]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.