How can I download image using Glide lib with volley response - android

I'm facing problem with glide image loading, currently I'm using the given code which I searched from stackoverflow, but not working with me,
Details:
is volley response I have string url and below code I'm using but working in my condition, need help
#Override
public void webServiceCompleted(JSONObject responseJson) {
Gson gson = new Gson();
message_model=gson.fromJson(responseJson.toString(),myModelClass.class);
String url= message_model.getMessage_image();
commonFuntions.mLoaderCancel(mContext);
Glide
.with(getApplicationContext())
.load(url)
.into(_ImageView);
}
But after loading the screen remains blank, even I can't using placeholder for it.

The way you are trying to load your image url is correct, Problem is with the url of the image, append "http://" in the beginning of the response url and then try your original code again. It should work.

This is for load imageurl into imageview using glide.
library for glide : compile 'com.github.bumptech.glide:glide:3.7.0'
Glide.with(getApplicationContext()).load(Stringurl)
.thumbnail(0.5f)
.crossFade()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(yourimageview);
but first check your response.

Related

How to remove a particular image URL from disk cache in Glide?

I am loading an image from remote URL into an ImageView with Glide. When I update the image, the content within that URL changes, but the URL location remains same. (This is as expected).
for eg. https://www.the-android-app.com/userid/121.jpg
Now I am showing image into ImageView using this code.
Glide
.with(this)
.load(profilePicUrl) //this is in String format
.diskCacheStrategy(DiskCacheStrategy.RESULT)
.skipMemoryCache(true)
.error(R.drawable.default_profile_pic)
.into(imgProfilePic);
When I update my profile pic, Glide is loading the same old pic from Cache. I need to remove cache entry for this URL before fetching the new image.
Edit:
The url always remains same, only the content inside it changes.
I'm using Glide 3.8.0
You can try signature(new ObjectKey(System.currentTimeMillis()))
Look in Custom cache invalidation for more information.
Example
GlideApp.with(this)
.load(imageUrl)
.signature(new ObjectKey(System.currentTimeMillis()))
.into(imageView);

Loading image in ImageView using volley library

I stored the path to my images in mysql db and was not sure if there's a way to load them in an imageView using volley library.
I'm able to parse string as json and display it in textView using volley string request queue but wasn't sure how I can get the path to display as image in my imageView. I would like to fetch the image using id.
Thanks in advance!
I always use the Glide to load images like this. Simply return the path like you do any other string. There is no need to load a bitmap with Volley, using Glide for this is simpler and better. Glide will handle for example image caching amongst other things.
This is all you need except from the Volley part.
ImageView imageView = findViewById(R.id.image);
String url = "www.foobar.com/" + path;
Glide.with(context).load(url).into(imageView);
Recently, I used Picasso library in my project and it worked fine and smooth. You can easily Load Image to ImageView from Url by using Picasso. Moreover, you can resize the original image to your desire size.
Example:
String mURL = "https:\/\/c.tribune.com.pk\/2017\/12\/1593389-vanga-1514310781-708-160x120.jpg";
ImageView Icon = (ImageView) findViewById(R.id.icon);
Picasso.with(context).load(mURL).resize(72, 72).into(icon);
Note: Using Picasso first you must import its library.
I used this: compile 'com.squareup.picasso:picasso:2.5.2'
use glide to display your image or you can use picasso
new ImageRequest(
url,
listener,
maxWidth,
maxHeight,
decodeConfig,
errorListener);
Response.Listener<Bitmap> listener = new Response.Listener<Bitmap>() {
#Override
public void onResponse(Bitmap bitmap) {
//here you set the bitmap to imageview
} };

Loading images in recyclerview with picasso from api

Add image in RecyclerView from api using picasso
Image loading using Picasso is very easy, you can do it like this way Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView); and in their website you can get every details. In your case you can parse every image URL and use RecyclerView to show them along with Picasso.
Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView)
In the new versions of Picasso you don't need the context anymore.
I'm using:
implementation 'com.squareup.picasso:picasso:2.71828'
In the new versions of Picasso used get()
Picasso latest version Picasso library: 2.71828
Picasso
.get()
.load("You Img Path Place Here")
.resize(width, height)
.noFade()
.into("Path set ImageView");
Used latest picasso version
implementation 'com.squareup.picasso:picasso:2.71828'
Try this
String img_url = "YOUR IMAGE URL";
if (!img_url.equalsIgnoreCase(""))
Picasso.with(context).load(img_url).placeholder(R.drawable.user_image)// Place holder image from drawable folder
.error(R.drawable.user_image).resize(110, 110).centerCrop()
.into("IMAGE VIEW ID WHERE YOU WANT TO SET IMAGE");
Happy coding.
You can load image using picasso like this way
Picasso.with(context).load(android_versions.get(i).getAndroid_image_url()).resize(120, 60).into(viewHolder.img_android);
https://www.learn2crack.com/2016/02/image-loading-recyclerview-picasso.html
Here ctx is context, list.getImage_full_path()) is image coming from server, in placeholder a static image is placed if image is not loaded, on error kent is name of image and into(servicecart_image) is placed in XML so image is loaded there
Picasso.with(ctx).load(list.getImage_full_path()).resize(160, 200).placeholder(R.drawable.kent)
.error(R.drawable.kent).into(servicecart_image);

Android Glide failing to load image

I am trying to load an image into an ImageView using the Glide library. The URL that I pass into the load() method points to an endpoint ('/api/user/5/logo'), which then returns the image. For some reason this doesn't seem to work.
However if I pass a URL that points directly to an image ('www.example.com/logo.png'), it works perfectly.
How do I get Glide to work perfectly with the required web service?
To recap, this works:
Glide.with(getContext())
.load("www.example.com/content/logo.png")
.centerCrop()
.placeholder(R.drawable.mark)
.into(imageView);
.. and this doesn't:
Glide.with(getContext())
.load("www.example.com/api/user/5/logo")
.centerCrop()
.placeholder(R.drawable.mark)
.into(imageView);
Any help would be greatly appreciated.
Try with this:
Glide.with(getContext())
.load("http://www.example.com/api/user/5/logo").centerCrop().into(imageview)

Load image from URL to imageView as well as Cache

Hi i am new beginner in android. I want to insert image in imageView from URL but whenever one time it is loaded from URL in imageView then second time it should be insert without internet means it would be stored in cache as well.
for this you can use picasso Library
You can download it from Picasso Library site simply put this jar file into libs folder. It will manage all property of Image.
http://square.github.io/picasso/
String imgURL = "Your URL";
ivmage = (ImageView) findViewById(R.id.imageView1);
Picasso.with(MainActivity.this).load(imgURL).into(ivmage);
You can use Picasso Library.
By Using Picasso, The Advantages are
Handling ImageView recycling and download cancelation in an adapter.
Complex image transformations with minimal memory use.
Automatic memory and disk caching.
To load Image from Url
Picasso.with(context).load(url).into(imageView);
Refer this link for Api : Picasso
you can use Glide https://github.com/bumptech/glide
Glide.with(this).load("imageURl").into(imageView);
I suggest picasso library for doing this. here is the detailed documentation of picasso library.
ex:
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
or you can make use of volley's ImageLoader. here you can find the documentation for Volley's image loading.
ex :
// Retrieves an image specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
new Response.Listener<Bitmap>() {
#Override
public void onResponse(Bitmap bitmap) {
mImageView.setImageBitmap(bitmap);
}
}, 0, 0, null,
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
mImageView.setImageResource(R.drawable.image_load_error);
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(request);
if you are using volley. then you have to cache images manually. picasso will cache images by default.

Categories

Resources