1

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.

Breed Hansen
  • 1,159
  • 5
  • 13
  • 21

2 Answers2

1

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.
karthikr
  • 97,368
  • 26
  • 197
  • 188
Brajendra Pandey
  • 2,280
  • 1
  • 16
  • 22
1

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.

Alexis C.
  • 91,686
  • 21
  • 171
  • 177
  • ZouZou, I know this tutorial. I can't load InputStream with gif file. – Breed Hansen Jun 11 '13 at 07:21
  • Shouldn't it be `openFileInput("frog.gif");` ? Are you sure that the gif file is in the right folder/place ? – Alexis C. Jun 11 '13 at 07:30
  • If I use "frog", it gives me divide zero error. If I use "frog.gif" I get no such file in directories error. But I am confident file is here. I exported to desktop and saw my eyes. – Breed Hansen Jun 11 '13 at 07:35
  • My files saved "frog" , I changed "frog.gif". But it is still same error. – Breed Hansen Jun 11 '13 at 07:40
  • Keep it with the name "frog.gif" for your file, now the error you have is more comprehensible. Are you sure that you're getting the file in the right place when you call `openFileInput("frog.gif");` ? – Alexis C. Jun 11 '13 at 07:44
  • Yes, I am sure. Because I can read `mp3` and `.png` files from this method. All files in same folder. (under `com.example.project/files` folder) – Breed Hansen Jun 11 '13 at 07:46
  • And the you rename the file name as frog.gif in your files folder ? That's very weird. – Alexis C. Jun 11 '13 at 07:50
  • Yes, I renamed. openFileInput returns null. My main problem is this. – Breed Hansen Jun 11 '13 at 07:53
  • read this please : http://stackoverflow.com/a/10262631/1587046 And try to closely follow the tutorial to see what's the error (store the gif file in assets folder and load it from there). – Alexis C. Jun 11 '13 at 07:59
  • I used this code and it works properly. InputStream stream = getAssets().open("bla.gif"); GifMovieView gmv = new GifMovieView(getApplicationContext(), stream); setContentView(gmv); – Breed Hansen Jun 11 '13 at 08:07
  • Ok cool so the error is that the program can't locate the file. So keep of using assets (which I think is the best choice) or try to know why the method can't find the file. – Alexis C. Jun 11 '13 at 08:13