I am running Android in Eclipse. the following line (from Camera.demo)
outStream = new FileOutputStream(String.开发者_如何学Cformat("/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
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.
精彩评论