How to check at runtime if an imageview came from a local or remote resource?

32 Views Asked by At

If I'm running as a third party library within an android application, and I want to check whether the imageviews on screen were loaded from locally bundled resources or were loaded from a remote uri - is there a way of doing this at runtime? Is there perhaps some clue in the view tree that would help me group the imageviews into these two broad categories? I see that the uri field itself isn't providing anything useful by reflection. I can ask developers to tag the imageviews but that creates a substantial overhead for them that I prefer to avoid.

1

There are 1 best solutions below

0
Gabe Sechan On

No. ImageViews hold Drawables. The view has no idea where that drawable came from. It doesn't even know what type of Drawable it is.

Also, using setImageUri to show a remote image is generally a code smell- that causes it to request and decode on the UI thread, which can be a cause of performance issues. You should never be doing that, and use an external image cache to download images and properly thread things. There's a few large image libraries out there that do it for you (Glide and Picasso being the big two)