Android WebView - loading images from cache

My webview saves a lot of cache on the SD card when I visit a site containing images and they do not show their format. When I try to open them, by default, the Android file manager says "File type not found." Then I changed the format of some of them (mostly large size) to .jpg and bingo, these are the images that I saw on the web page.

Punchline: I want to open images from those sites that were saved as a cache in another action, I will need to continue to rename all the cache files to .jpg, then call them or is there another way to do this.

Thanks.

0
source share
1 answer

You can use BitmapFactory to open these image files. You may try:

- decodeFile(String pathName) 

If there is a problem with the extension, try decodeStream (InputStream is) , it will get an InputStream , and it should work.


You can specify the folder with the file:

 File f = new File(Environment .getExternalStorageDirectory() .getAbsolutePath()); File[] files = f.listFiles(); for (File file : files){ //Do something with this file } 
+1
source

Source: https://habr.com/ru/post/924062/


All Articles