【问题标题】:Load password protected image to imageview with Picasso Image loader Library in android使用 android 中的 Picasso 图像加载器库将受密码保护的图像加载到 imageview
【发布时间】:2017-07-31 16:40:14
【问题描述】:

我得到一个受密码保护的图像 url。我知道如何使用 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;

        }

【问题讨论】:

  • 如何使用身份验证器?你能给我们看看吗?你如何将密码传递给url?

标签: android


【解决方案1】:

我相信这就是您正在寻找的。帖子说可以使用 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);

【讨论】:

  • 感谢您的回答,但您能告诉我最后如何将图像设置为图像视图吗?
  • @Akshaykumar 你有图片的网址吗?检查我更新的答案。
  • 通过这种方式我们可以正常进行,但是我的网址是受密码保护的,所以如何做到这一点是个问题。
  • 我的答案中的链接有详细信息。你可以照着做。您必须使用 Okhttp 进行身份验证。
猜你喜欢
  • 2019-06-27
  • 2014-03-12
  • 2016-09-26
  • 1970-01-01
  • 2012-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-14
相关资源
最近更新 更多