【问题标题】:Picasso load image on API 17 - Error HTTP 504Picasso 在 API 17 上加载图像 - 错误 HTTP 504
【发布时间】: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 linkthis link 中尝试了解决方案,并将 URL 更改为 http,但没有任何效果。我还发现 this post 在谈论一些协议更改,但我不知道它的含义或是否相关。

【问题讨论】:

    标签: android kotlin picasso


    【解决方案1】:

    我从this post 找到了解决方案。它说通过 Google Play Services 更新 Android 的安全提供程序来启用 TLSv1.2 协议。

    首先给app build.gradle添加依赖:

    implementation 'com.google.android.gms:play-services-auth:17.0.0'
    

    然后

    private fun updateAndroidSecurityProvider(callingActivity: Activity) {
            try {
                ProviderInstaller.installIfNeeded(this)
            } catch (e: GooglePlayServicesRepairableException) {
                // Thrown when Google Play Services is not installed, up-to-date, or enabled
                // Show dialog to allow users to install, update, or otherwise enable Google Play services.
                GooglePlayServicesUtil.getErrorDialog(e.getConnectionStatusCode(), callingActivity, 0)
            } catch (e: GooglePlayServicesNotAvailableException) {
                Log.e("SecurityException", "Google Play Services not available.")
            }
        }
    

    创建并调用函数后,我可以显示图像了。

    【讨论】:

      猜你喜欢
      • 2020-02-14
      • 1970-01-01
      • 2022-01-07
      • 2019-04-16
      • 2016-07-06
      • 2017-04-21
      • 2023-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多