Reputation: 549
My app was working fine till i migrated to new version of Picasso, so android studio told me i should change the .with methods to .get() so i changed it and now it won't load images, and doesn't give me any errors, here is my code:
Picasso.get().load(image).error(R.drawable.placeholder).placeholder(R.drawable.placeholder).centerCrop().resize(720,720).into(this.image_view_wallpaper_image);
public static void imageDownload(Context ctx, String url,String name){
Picasso.get()
.load(url)
.into(getTarget(url,name,ctx));
}
//target to save
private static Target getTarget(final String url, final String name, final Context ctx){
Target target = new Target(){
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
new Thread(new Runnable() {
@Override
public void run() {
File file = new File(Environment.getExternalStorageDirectory().toString() + ctx.getResources().getString(R.string.DownloadFolder) + name);
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, ostream);
ostream.flush();
ostream.close();
} catch (IOException e) {
Log.e("IOException", e.getLocalizedMessage());
}
}
}).start();
Log.v("ok","onBitmapLoaded");
}
public void loadBitmap(String url) {
if (loadtarget == null) loadtarget = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
tempBmp=bitmap;
new WallpaperOperation().execute("");
}
@Override
public void onBitmapFailed(Exception e, Drawable errorDrawable) {
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
Picasso.get().load(url).into(loadtarget);
}
before updating it was like this and was working perfectly :
Picasso.with(getApplicationContext()).load(image).error(R.drawable.placeholder).placeholder(R.drawable.placeholder).centerCrop().resize(720,720).into(this.image_view_wallpaper_image);
obviously it's not whole code I just put the sections that I've changed, i didn't get any errors, Picasso is at the latest version but it won't show anything, i also migrated to android x too.
Upvotes: -1
Views: 908
Reputation: 2562
As per comments, problem was http endpoint problem. You have two options:
Option 1. Replace your url
's http with https beofre passing to Picasso
String imageUrl = "http://www.myurl.com/images/earth.png";
imageUrl = imageUrl.replace("http","https");
Picasso.get().url(imageUrl).....
Option 2. Use a http client that supports Http connections, for example OkHttp. To use it add the dependency to gradle.build
implementation("com.squareup.okhttp3:okhttp:4.1.1")
Upvotes: 2
Reputation: 84
Use Glide library instand of Picasso because Glide is faster then Picasso and some other features.
dependencies {
implementation 'com.github.bumptech.glide:glide:3.8.0'
}
Usage
Glide.with(context)
.load(url)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
holder.mProgressBar.setVisibility(View.GONE);
holder.mImgProduct.setImageResource(R.drawable.ic_cart);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
holder.mProgressBar.setVisibility(View.GONE);
return false;
}
})
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(holder.mImgProduct);
Upvotes: -1