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" />
Related
I am making two API calls parallel in the following way.
Single.zip(API1.subscribeOn(Schedulers.io()),
API2.subscribeOn(Schedulers.io()), Bifunction())).subscribe();
I would want to load a bitmap from an URL and send back the bitmap. Something like this
Single.zip(API1.subscribeOn(Schedulers.io()),
API2.subscribeOn(Schedulers.io()), getImageBitmap(), Function3())).subscribe();
In the method getImageBitmap I am trying to return Single<Bitmap>. Something like this.
Single.create(new SingleOnSubscribe<Bitmap>() {
#Override
public void subscribe(final SingleEmitter<Bitmap> emitter) throws Exception {
Glide.with(context).asBitmap().load(url)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.error(R.drawable.ic_login_error).addListener(new RequestListener<Bitmap>() {
#Override
public boolean onLoadFailed(#Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
emitter.onSuccess(null);
return false;
}
#Override
public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
emitter.onSuccess(resource);
return false;
}
});
}
}).subscribeOn(AndroidSchedulers.mainThread());
I am not getting any results out of this. How to get Bitmap from Glide in the following approach?
While loading the image from Glide, we should either call the .submit() method or .into(...) in order to successfully get the bitmap or load the image.
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
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.
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.
I am using Glide to download and cache images on Android. Everything works well except the fact that I don't want to load the bitmaps directly into the ImageView, I don't want to have the fade animation, neither image placeholders.
All I want is to create a global method which will help me to download the image all over the application.
public class MyApp extends Application {
public static void downloadImage(String url, final OnImageLoadedCallback callback) {
// And how to implement the listener ?
RequestListener<String, Bitmap> requestListener = new RequestListener<String, Bitmap() {
#Override
public boolean onException(Exception exc, String string, Target<Bitmap> target, boolean isFirstResource) {
callback.onDone(null);
return false;
}
#Override
public boolean onResourceReady(Bitmap bitmap, String string, Target<Bitmap> target, boolean isFromMemoryCache, boolean isFirstResource) {
callback.onDone(bitmap);
return false;
}
};
Glide.with(context)
.load(url)
.asBitmap()
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.listener(requestListener);
}
}
The problem is that I don't know how to implement the listener. RequestListener isn't called at all.
Loads in Glide don't start until you make a call to into. The RequestListener interface observes requests, but isn't typically meant for handling results. Instead of using RequestListener, consider having your callback implement the Target interface and pass it in using into.
Alternatively you could just extend SimpleTarget and pass it in to each request in the same way you're trying to use RequestListener:
Target target = Glide.with(context)
...
.into(new SimpleTarget<Bitmap>(width, height) {
#Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
callback.onDone(resource);
}
#Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
callback.onDone(null);
}
});
// At some point later, if you want to cancel the load:
Glide.clear(target);
You will want to provide a width and a height so that Glide can downsample and transform images appropriately. You may also run in to issues with cancellation if you're displaying these Bitmaps in views, in which case I'd strongly recommend making the view available to your loading API and passing the view to into which will handle sizing and cancellation for you.
I use Glide 3.7.0 and download images this way:
it is important to note - it executes asyncroniously
Glide.with(this)
.load(url)
.downloadOnly(new SimpleTarget<File>() {
#Override
public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation) {
LOGGER.debug("Photo downloaded");
}
});
When I need to show cached image, I use the same url and DiskCacheStrategy.SOURCE:
Glide.with(this)
.load(url)
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.into(imageView);
It is now even simpler on Glide 4.9.0.
Glide.with(this)
.downloadOnly()
.load(url)