Glide Version: 4.7.1
Integration libraries: okhttp 4.7.1
I am trying to access and image (PNG) on a server but the request is not even sent. Can the URL formation crash the lib without an error message ? Or maybe it's sent but there is neither a failure response in the Request Listener nor a success.
How can i trace the problem ?
I have tried following the execution chain but i can only see the preparation of the request.
I monitor the network with Charles and i can't see the request sent out
I am using a basic GlideApp module call
GlideApp.with(mApplicationContext).load(url).dontAnimate().listener(new RequestListener<Drawable>() {
#Override
public boolean onLoadFailed(#Nullable final GlideException e, final Object model, final Target<Drawable> target, final boolean isFirstResource) {
// Nothing arrives here
return false;
}
#Override
public boolean onResourceReady(final Drawable resource, final Object model, final Target<Drawable> target, final DataSource dataSource, final boolean isFirstResource) {
// Nothing arrives here
return false;
}
}).into(imageView);
Thanks
OK i figured it out.
I was passing an newly created ImageView in code that i was using to store the returned image temporarily. This had no dimensions.
This worked fine with the Picasso library, but stopped working when i changed to Glide. So passing a real ImageView that is visible in a layout, works.
Picasso had another issue with PNG's which is why i switched.
Related
I'm try to download multiple images from server using the Glide
here is code
for (String url : list) {
RequestOptions requestOptions = RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL);
Glide.with(this)
.asBitmap()
.load(url).addListener(new RequestListener<Bitmap>() {
#Override
public boolean onLoadFailed(#Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
Log.e("ProgressCheck", "onResourceReady: " + progress);
return false;
}
})
.apply(requestOptions)
.submit();
}
Code run perfectly but when the downloading image failed (any reason wifi disconnected or server not responding.etc) how to send the same request again??
or is there the better way download multiple images using Glide
I suggest you to make a separate method of loading image via glide.
Here is the pseudo code
private void loadImage(String URL){
// Your Glide code
//Inside onLoadFailed call loadImage() again.
//For number of attempts you can maintain one int and increment that on every attempt.
}
If error or fallback strategies are not useful to you, then in 4.3.0 version you can starting a new request on failure:
Glide.with(fragment)
.load(url)
.error(
Glide.with(fragment)
.load(url))
.into(imageView);
Learn more at https://bumptech.github.io/glide/doc/options.html#starting-a-new-request-on-failure
I am making a project for image loading but whenever I try to load an image into circle image view through glide but whenever I run the app, the image view goes blank and error comes up from glide.
dp = view.findViewById(R.id.circleView);
GlideApp
.with(getActivity())
.load(serverResponse.getMessage().getPic())//C:/Apache24/htdocs/app2/User Files/User Id-102/User id 102.jpg
.listener(new RequestListener<Drawable>() {
#Override
public boolean onLoadFailed(#Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
// log exception
Toast.makeText(getActivity(), "Error loading image", Toast.LENGTH_SHORT).show();
Log.v("glide", "Error loading image", e);
return false; // important to return false so the error placeholder can be placed
}
#Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
return false;
}
})
.into(dp);
Log
2018-11-02 19:20:08.709 31664-31664/com.example.user.myapplication W/Glide: Load failed for C:/Apache24/htdocs/app2/User Files/User Id-102/User id 102.jpg with size [200x200]
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
2018-11-02 19:20:08.718 31664-31664/com.example.user.myapplication V/glide: Error loading image
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
I cannot figure out actually from where the error is occurring.
I found the solution, I wanted to load file from the localhost server of my pc and I was using pc file system reference which glide does not support but when I passed the IP address along with the file address (e.g. http://(your ip like 192....)/your localhost project folder/image.jpg) and it worked.
It seems you're using an invalid image reference. Glide can load resources from the internet (http or https) or from the device's (mobile/tablet) file system. But it seems your response contains a reference to an image file on your PC's file system.
Thanks for viewing my question here.
I am using Glide to fetch image from Firebase storage, basically i am using url to get the image from storage. First day it was working fine but suddenly it stopped fetching image. i did not touch the code. I have checked many answer but still i could not fix the issue. Please let me know where i am doing mistake.
This is gradle app file.
compile 'com.github.bumptech.glide:glide:3.8.0'
compile 'com.android.support:support-v4:23.4.0'
This is the Glide code i use in my Adapter java file
Glide.with(context).load(mproduct.get(position).getUrl()).into(viewHolder.pic);
Internet permission is there
<uses-permission android:name="android.permission.INTERNET" />
If it is not loading an image, there must be an error!
Check out the reason using listener:-
Glide.with(context)
.load(mproduct.get(position).getUrl())
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
// Here you will get the cause of error...
return true;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
// do something
return true;
}
})
.into(viewHolder.pic);
Please try with Piccaso
You can try below code..
Picasso.with(getApplicationContext()).load(mproduct.get(position).getUrl()).error(R.drawable.demo_image).into(viewHolder.pic);
dont forget to add dependency for Piccasso.
Right now I am using Glide-library to load the image in Android Wear. It doesn't load the image in most of the times. However, it loads image sometimes. Don't know what going wrong in my code.
Note Wear is connected to the device via Bluetooth and I successfully get JSON response of Webservice in Android Wear via Broadcast Receiver from mobile. All data are displayed properly in wear except the images.
Glide.with(mContext)
.load("http://www.hanamoflorist.ca/images/uploads/Spring5InchesCubeVaseArrangement$45.00.jpg")
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
Log.e("exception in image", "" + e);
Toast.makeText(mContext, "" + e, Toast.LENGTH_LONG).show();
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
}).error(R.drawable.ic_placeholder_image)
.into(((ItemViewHolder) holder).ivCardImage);
I think you should use, DaVinci for image loading in Wearable,
DaVinci.with(context).load("Your Url").into(imageView);
Make sure you use the same playservices version as the library,
You will be able to integrate the same by adding this to your gradle:
wear :
compile ('com.github.florent37:davinci:1.0.3#aar'){
transitive = true
}
Mobile:
compile ('com.github.florent37:davincidaemon:1.0.3#aar'){
transitive = true
}
Hope you will get what you want.
The issue is due to socket time out...
You can resolve it using Glide itself. You just need to use Glide with OKHttp3, and set Timeout Limit for OkHttpClient.
In your module dependency
compile 'com.github.bumptech.glide:glide:3.7.0'
compile ('com.github.bumptech.glide:okhttp3-integration:1.4.0'){
exclude group: 'glide-parent'
}
Customize glide settings
public class MyGlideModule implements GlideModule {
#Override
public void applyOptions(Context context, GlideBuilder builder) {
}
#Override
public void registerComponents(Context context, Glide glide) {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
// set your timeout here
builder.readTimeout(30, TimeUnit.SECONDS);
builder.writeTimeout(30, TimeUnit.SECONDS);
builder.connectTimeout(30, TimeUnit.SECONDS);
OkHttpUrlLoader.Factory factory = new OkHttpUrlLoader.Factory(client);
glide.register(GlideUrl.class, InputStream.class, factory);
}
}
In manifest put below code
<meta-data
android:name="YourPath.MyGlideModule"
android:value="GlideModule" />
I have a weird bug with Glide and i'm not sure what to do about it. Basically I have this function, which loads images from reddit.com/r/earthporn/
newsdata.data.children[position].data.url is a list of urls
public void displayImage(final int position) {
Drawable d = view.getContext().getResources().getDrawable(R.drawable.ic_collections_white_24dp);
System.out.println(newsData.data.children[position].data.url);
Glide.with(view.getContext())
.load(newsData.data.children[position].data.url)
.asBitmap()
.listener(new RequestListener<String, Bitmap>() {
#Override
public boolean onException(Exception e, String model, Target<Bitmap> target, boolean isFirstResource) {
displayImage(position + 1);
//todo: make sure we don't run into a index out of bounds.
return false;
}
#Override
public boolean onResourceReady(Bitmap resource, String model, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
})
.centerCrop()
.error(d)
.into(new BitmapImageViewTarget(view.getImageView()) {
#Override
protected void setResource(Bitmap resource) {
super.setResource(resource);
view.setImageBitmap(resource);
wallPaperBitmap = resource;
System.out.println(resource);
}
});
}
Android can't load every single image that appears on the subreddit. When that happens, I load the next image down. On a run today, it will load this image http://imgur.com/HOSg2FC, call an exception, and then load this http://i.imgur.com/baluFH7.jpg
OnCreate, this code will run as expected. It runs, hits the exception, calls displayImages() again and sets the correct Image. (Please, let me know if there's a better way to do this)
OnResume/onStart is where the problem lies. The code will run, hit the exception, place the error drawable, call displayImages again but not change the imageview. setResource(bitmap resource) will also give me the correct bitmap but will not let me update the imageview at all.
Basically, it freezes the imageview to the error drawable, or to a blank white screen if there is no drawable and won't let me change it.
Calling onResume with the following code:
if(wallPaperBitmap != null) {
view.setImageViewPicture(wallPaperBitmap);
//view.showButtons();
System.out.println("bitmap != null");
}
else {
retrieveImage(SubReddit.Earth);
System.out.println("bitmap = null");
}
Will set the correct picture.
I thought maybe this might be a problem with the cache so I tried using diskcachestrategy.none but that didn't help either. As a last resort, I could probably refresh the screen once setResource is called with the updated bitmap or just use Picasso but I'd rather avoid that.
Any help is appreciated!
Edit: I'm also getting the error: D/skia﹕ --- SkImageDecoder::Factory returned null onStart
Glide may restart failed requests in onStart, which would trigger the failure, then set the error Drawable. To fix this, you should do two things:
Always call clear() on Views and Targets before calling setImageResource/setImageDrawable yourself (outside of onResourceReady). Calling clear() will prevent Glide from managing that View/Target, which in turn will stop Glide from restarting the loading in onStart.
If you ever keep a reference to a resource loaded by Glide (usually a Bitmap or a Drawable, you need to make sure to null out your reference when the Target's onLoadCleared or onLoadFailed methods are called. This isn't directly related to this issue, but it's an error in your code above and can lead to weird errors if Glide re-uses the Bitmap while you're referencing it.