idish
idish

Reputation: 3260

File operations doesn't work sometimes

Something very strange is happenning in my app. I am creating 2 folders in the SD card if they not exist, and downloading some images from a URL if they not exist in the SD card. Sometimes, when I run the application, the program checks if the folders exists and also the images, as they are exists, it continues and there's nothing wrong. But often when I run the application, it alerts me that the folders not exists and that it didn't even managed to create those folders, and afterwards I'm getting a "File not found exception" when it tries to download the images who already exists in my SD card.

P.S: I tried it with 2 devices and the same happens, sometimes works, sometimes doesn't.

What could be the problem here?

Upvotes: 0

Views: 143

Answers (1)

user370305
user370305

Reputation: 109247

Actually before accessing files from external storage you have to check whether External storage is present (Available) or not on device (It possible if device's sdcard is mounted on System). For this You have to check the sate of External Storage as Mounted or Not.

Look at this Link for more info..

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

Now solution:

If you find external storage is not available then you can store your files at Internal Storage on temporary basis (Then you can move these files to External Storage when it present).

So My link also help you in how to access Internal Storage in Android.

Upvotes: 1

Related Questions