How to leverage Glide cache for loading notification icons? Those are IconCompat used in the Person object in the MessagingStyle notifications and Shortcuts. Also, Bubbles require using both of those.
I used Glid as fallowing:
private IconCompat loadIcon(String url) throws ExecutionException, InterruptedException {
RequestOptions requestOptions = new RequestOptions().override(ADAPTIVE_BITMAP_SIZE);
Bitmap bitmap = Glide.with(G.app).asBitmap().apply(requestOptions).load(url).submit().get();
return IconCompat.createWithAdaptiveBitmap(bitmap);
}
I got several questions about this solution
- What should be the size of
ADAPTIVE_BITMAP_SIZE? - When will the bitmap get recycled?
- How to handle errors in loading the bitmap?
Create a custom
TargetWrapperfor the async loading icon. The config your Glide using your TargetWrapper instance.Helper function for async loading bitmap then wrap into Icon
Here is the Glide image request function with retrieving bitmap with a callback.
CustomTargetWrapper class for async loading bitmap.