简体   繁体   中英

Android WebView - Load Images from cache

My webview saves lot of cache on SD Card when I visit a site which contains images and they don't show their format. When I try to open them, the default Android file manager says "File type not found". Then I changed the format of some of them(mostly the big size one) to .jpg and bingo, they are the images I saw on the webpage.

Punchline: I want to open the images from that sites that are saved as cache, in another activity, would I have to go on and rename all the cache files to .jpg then call them or there is another way to do it.

Thank you.

You can use the BitmapFactory to open these images files. You can try:

- decodeFile(String pathName)

If it gives some problem with the extension, try decodeStream (InputStream is) , it receive an InputStream and it should work.


You can list a folder with File:

File f = new File(Environment
          .getExternalStorageDirectory()
          .getAbsolutePath());

File[] files = f.listFiles();
for (File file : files){
   //Do something with this file
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM