【发布时间】:2021-07-18 00:40:19
【问题描述】:
我想使用带有毕加索的 Unsplash 网站显示随机图像。但是,图像不会显示在 API 17 物理平板电脑上。它确实显示在 API 28 模拟器上。
如何在 API 17 设备上使用 Picasso 显示图像?
毕加索版:
implementation 'com.squareup.picasso:picasso:2.71828'
加载图片:
private const val RAND_IMAGE_URL:String = "https://images.unsplash.com/photo-1617721042477-7c5c498e7dbf?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=800&ixlib=rb-1.2.1&q=80&w=800"
// Load the random image
val image = findViewById<ImageView>(R.id.iv_image)
Picasso.get().load(RAND_IMAGE_URL)
.error(R.drawable.ic_error_outline_72)
.into(image, object : Callback {
override fun onSuccess() {
// successfully loaded
// hide progress bar
progressBar.visibility = View.GONE
}
override fun onError(e: Exception?) {
// display error message
Log.e(TAG, "error loading image", e)
// hide progress bar
progressBar.visibility = View.GONE
}
})
错误:
com.squareup.picasso.NetworkRequestHandler$ResponseException: HTTP 504
at com.squareup.picasso.NetworkRequestHandler.load(NetworkRequestHandler.java:51)
at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:219)
at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:175)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
at java.util.concurrent.FutureTask.run(FutureTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)
at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:354)
我在this link、this link 中尝试了解决方案,并将 URL 更改为 http,但没有任何效果。我还发现 this post 在谈论一些协议更改,但我不知道它的含义或是否相关。
【问题讨论】: