Android WebView - Load Images from cache - android

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
}

Related

Why cant i load the image in picasso?

The actual code is very simple like this but doesnt works!!
File f = new File("file://E:/test.jpeg");
Picasso.with(this).load(f).
into(avatar);
File f = new File("file://E:/test.jpeg");
First, Android does not have drive letters, let alone an E: drive. That is not a valid filesystem path to any file on any Android device.
Second, the File constructor takes a filesystem path, not a Uri with a scheme (e.g., file://).
Its important to know that the file you are accessing has to be on your DEVICE and NOT from your computer. There is no such directory as a E: drive on phones.
You have a few options. Store the image online, and load it with Picasso (the easiest).
Picasso.with(getActivity())
.load("http://www.image_url.com/image.png")
.into(avatar);
Or, you can get the file path of an image, and then use that with picasso.
File file = new File("path-to-image/image.png")
Picasso.with(getActivity()).load(file).into(avatar);
How do you get the path-to-image of an image on your device?
You can follow this http://www.limbaniandroid.com/2014/03/how-to-get-absolute-path-when-select.html

Copy images from Assets to Cache (ImageLoader)

I need make copy from assets to cache pictures.
I have got MD5 file name in assets (image http url).
I made copy as here:
DiskCache diskCache = ImageLoader.getInstance().getDiskCache();
File fileDirectory = diskCache.getDirectory();
copyAssets(context, fileDirectory);
I try read file with UniveralImageLoader as:
ImageLoader.getInstance().displayImage(castle.getImageUrl(), this.castleImage, imageOptions);
but image isn't read.
Any sugestions?
SOLUTION
cache.save(uri, in, copylistener)

Open all image from specific folder in Android default gallery

My requirement is to open all images and video's of specific folder.
I have refereed this link, Now I am able to show a image in gallery but I want to show all images from a specific folder. Almost all link I have tried on stack but did not get success.
You can set path in File object initialize at that time.
File folder = new File("/sdcard/Photo/"); in this tutorial default path is /sdcard/photo/ at this place you can set your path then get your files.
I sinc it is not good idea but you may write your own searcher in all files on mobile phone for example
public ArrayList<File> getAllphotos(String path){
ArrayList<File> photoPath = new ArrayList<>();
File yourDir = new File(path);
for (File f : yourDir.listFiles()) {
String mas[] = f.toString().split("\\.");
if(mas[mas.length - 1].equalsIgnoreCase("png") || mas[mas.length - 1].equalsIgnoreCase("jpeg")){//or other formats
//it is picture
photoPath.add(f);
}
}
return photoPath;
}
call this wis iternal and external storage

How to read .gif file from internal storage?

I want to read .gif file from internal storage. I can read image, mp3 but not .gif. Actually I am searching global way to read any types of file.
Regards
Edit:
private void globalGif() throws FileNotFoundException{
FileInputStream fis = openFileInput("frog");
GifMovieView gmv = new GifMovieView(getApplicationContext(), fis);
setContentView(gmv);
}
I use this code but it shows this error. divide by zero fis haven't gif file.
If you want to read gif files, take a look at the Movie class.
Here's a nice tutorial which show you how to load a gif and show it.
you can find the path of image following way
File file= new File(Environment.getExternalStorageDirectory()
+ "/Images/a.gif");
But you can not set this gif image to ImageView the gif file is show in webView.

Android: get route of file

I need the route of a pdf file in my Android Project.
The file could be in raw or in assets folder.
I need to get the route because I must call using the File Class
Ex: File file = new File(path);
Thanks
Image:
http://img19.imageshack.us/img19/2303/capturaww.png
I am not quite sure what you mean, assuming you want to read to PDF file in your assets (res file) look here
Access PDF files from 'res/raw' or assets folder programmatically to parse with given methods
But if you want to get the file path of a folder, then look here
how to get file path from sd card in android
How to get the file path from URI?
Here is an example of how to get a file path (taken from the third link)
File myFile = new File(uri.toString());
myFile.getAbsolutePath()

Categories

Resources