开发者

writing to sdcard not working

开发者 https://www.devze.com 2023-01-16 12:17 出处:网络
I am running Android in Eclipse. the following line (from Camera.demo) outStream = new FileOutputStream(String.开发者_如何学Cformat(\"/sdcard/%d.jpg\",

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号