Unable to load image from device using glide in Android 10 (Q) - android

Glide is not loading image picked from gallery.
It always show following error despite giving write and read permission.
java.io.FileNotFoundException: /storage/emulated/0/Pictures/JPEG_20200120103701_3365226945725752825.jpg: open failed: EACCES (Permission denied)

Add this line android manifest
android:requestLegacyExternalStorage="true"

You have to pass the related uri, not the path,
Glide.with(context).load(model.photoUri).into(image)
By this you don't need to add
android:requestLegacyExternalStorage="true"
in your Manifest file.

No Gallery app will have given you that File path.
So you have been messing around with something like getRealPathFromUri().
That will not do on Q as nobody has access to that Pictures path.
Better use the obtained uri directly.
You should do that below Q too.

Make file instance and pass file's uri that you want to load into ImageView
You can also use RequestListener to trace the error in case of failure
Glide.with(context)
.load(new File(fileUri.getPath())) // Uri of the picture
.into(imageview)
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
Log.e("xmx1","Error "+e.toString());
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
Log.e("xmx1","no Error ");
return false;
}
});
Make sure you have added
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
inside your application tag ```
<application
android:name=".App"
android:allowBackup="false"
android:icon="#mipmap/ic_launcher"
android:requestLegacyExternalStorage="true"
... >

Related

How to request again if image download failed using glide

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

Failed to load resource when loading image

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.

Glide for Android - Url request is not sent out, no exception

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.

Glide gif doesnt play

I want to load a gif into an imageview, it is displayed but doesn't start playing. I use this code:
Glide.with(context)
.load("https://media.giphy.com/media/7rj2ZgttvgomY/giphy.gif")
.into(imageView)
I've also tried adding .asGif() but in that case image is not displayed at all. I'm using glide 3.8.0
try this.
Glide.with(context)
.load(imageUrl)
.asGif()
.placeholder(R.drawable.loading2)
.crossFade()
.into(imageView);
In my case I had set the imageview dimensions to match_parent and specifying it in dp did it for me.
Not sure why exactly match_parent doesn't work in a dialog, playing GIFs, probably something to do with the scaling, if this is the case then using scaleType:fitXY should work too
You can also try
Glide
.with(context)
.load(gifUrl)
.asGif()
.error(R.drawable.full_cake)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)`
.into(imageViewGif);
Change your gif your to https://i.giphy.com/media/7rj2ZgttvgomY/giphy.webp
Glide.with(context)
.load("https://i.giphy.com/media/7rj2ZgttvgomY/giphy.webp")
.asGif().into(imageView);
Also you can try GIFView
You can refer to : https://github.com/bumptech/glide/issues/1059
If you don't find it, you can change the lastest version of Gline
repositories {
mavenCentral()
maven { url 'https://maven.google.com' }
}
dependencies {
compile 'com.github.bumptech.glide:glide:4.2.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'
}
I hope you can find solution.
There is nothing wrong with your code. You could check if you have Internet permission.
<uses-permission android:name="android.permission.INTERNET" />
Your internet speed might be slow and Glide might be taking too much time to load so by that time you could add a placeholder image using :
.placeholder(android.R.color.holo_green_dark)
Or you could add Listner to the Request using
.listener(new RequestListener<String, GlideDrawable>() {
#Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
#Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
})
And see what is the Exception.

Suddenly Glide is failing to get image from url

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.

Categories

Resources