views:

28

answers:

1

I am running Android in Eclipse. the following line (from Camera.demo)

outStream = new FileOutputStream(String.format("/sdcard/%d.jpg", 
    System.currentTimeMillis()));

fails and returns the following error:-

FileNotFound - permission denied.

Is there anything I can do to correct this? I have assumed that the sdcard directory is present in the emulator. Thanks Ron

A: 

The AVD you're running has to be explicitly configured with SD card support or it will behave as if there isn't one. More information here.

Your application also needs the WRITE_EXTERNAL_STORAGE permission.

Side note: You should be calling Environment.getExternalStorageDirectory() to get the SD card's path instead of hard-coding /sdcard. It returns null if there's no storage available. You can use the canWrite() method on the returned value to determine if it's actually something you can use for storage.

Blrfl
Thanks - that has fixed it. I appreciate the help.
Ron Etherington