I want to load image from URL with picasso android library and show it to view but I get an error only in android 7.0 Nougat.
The URL of the image uses HTTPS. In my other project with the same image URL I didn't get the error if I run in real device 7.0 nougat, but it still error if I run in emulator 7.0 Nougat.
I try to other URL image from different domain and I didn't get the error too.
how do I fix it?
Picasso.get().load("My_URL_Image")
.resize(200,200)
.centerInside()
.placeholder(R.drawable.ic_default)
.error(R.drawable.ic_default)
.into(holder.imageView, object : Callback{
override fun onSuccess() {}
override fun onError(e: Exception?) {
e?.printStackTrace()
}
})
W/System.err: com.squareup.picasso.NetworkRequestHandler$ResponseException: HTTP 504
W/System.err: at com.squareup.picasso.NetworkRequestHandler.load(NetworkRequestHandler.java:51)
W/System.err: at com.squareup.picasso.BitmapHunter.hunt(BitmapHunter.java:219)
W/System.err: at com.squareup.picasso.BitmapHunter.run(BitmapHunter.java:175)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
at com.squareup.picasso.Utils$PicassoThread.run(Utils.java:354)
You will have to set a networkSecurityConfig
in your AndroidManifest.xml
file like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config">
</application>
</manifest>
After that in your xml
folder you will create new file as per above code mention name network_security_config
to enable all request without encryptions:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
Now your app will make all requests for any kind of connections. For more information read this.
I hope it'll help you....!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With