There are two situations I load images, first, just directly from the internet, and second, load images that are downloaded in the device. And whenever I load, 8~9 out of 10
You can turn on Picasso logs using Picasso.with(Context).setLoggingEnabled(true)
. You will probably see an error message with a reason there.
It's also worth logging the URL you are using and trying it a browser, just in case.
In Picasso you shoud pass url in .load()
method to load picture from internet and object of File
type to load picture from device storage.
So if the picture is stored on device load it like this:
Picasso.with(activity)
.load(new File(path))
.placeholder(R.drawable.thumbnail_placeholder)
.resize(width,height)
.into(imageView);
And use this code to load picture from internet:
Picasso.with(activity)
.load(path)
.placeholder(R.drawable.thumbnail_placeholder)
.resize(width,height)
.into(imageView);
Check if you have these permissions in the manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET"/>
You can use Picasso.with(Context).setLoggingEnabled(true)
to enable debugging so as to troubleshoot the exact cause .
If the log has something like Error 504
try using try using
android:usesCleartextTraffic="true"
in Application tag of your manifest. It worked for me
Answered here
check Internet permission in manifaest
<uses-permission android:name="android.permission.INTERNET"/>
If anything not works, it is because of the some problem with the servers that are hosting images, their url does not directly take you to the image, but in backend something else is working, it may open in chrome or other browser, but not for sure in picasso it will load, so you may try this code :
final OkHttpClient client = new OkHttpClient.Builder()
.protocols(Collections.singletonList(Protocol.HTTP_1_1))
.build();
final Picasso picasso = new Picasso.Builder(this)
.downloader(new OkHttp3Downloader(client))
.build();
Picasso.setSingletonInstance(picasso);
where the OkHttp3Downloader instance is supplied by this library. https://github.com/JakeWharton/picasso2-okhttp3-downloader