11

I have added this line in the AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

However, when I run code to write to the sdcard , I get this Error:

02-19 13:24:46.760: E/CameraTest(598): /mnt/sdcard/image.jpg: open failed: EACCES (Permission denied)

How do I solve this problem?

EDIT: I am using the Android Emulator with SDCard added.

EDIT-2: I know what the problem is now: I have called the function Environment.getExternalStorageState() and I get "removed". Anyone knows how to fix this and make the state MEDIA_MOUNTED

Thank You!

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
  • check [this][1] and [this][2] [1]: http://stackoverflow.com/questions/8854359/android-open-failed-eacces-permission-denied [2]: http://stackoverflow.com/questions/9334090/failed-to-save-image-to-sdcard – George Feb 19 '12 at 18:32
  • @thinksteep : yes the sd card is added. I am using the emulator by the way. – Saher Ahwal Feb 19 '12 at 19:44
  • @thinksteep : apparently when I print out the getExternalStorageState I get "removed" so how to I mount the SD card? – Saher Ahwal Feb 21 '12 at 07:29

4 Answers4

7

Ok So I have solved this. It was a problem I faced with mounting the sdcard and that android doesn't allow spaces in the path!

Here is a good procedure to follow (if eclipse is also used) : http://www.brighthub.com/mobile/google-android/articles/33240.aspx

NOTE: in case the path has a space in it, move the sdcard image file to somewhere else and then run the emulator command with the sdcard and everything should work fine!

Saher Ahwal
  • 9,015
  • 32
  • 84
  • 152
3

It might be more simple than that. I missed to configure the emulator so that it had a SD-card. Once I added a SD-card in the device, everything went well.

Regards, Jonas

Jonas
  • 103
  • 5
2

I notice that this problem can occur if you are using an Android 6.0 emulator, Android added new permission model for (Marshmallow).

Trick: If you are targeting version 22 or below, your application will request all permissions at install time just as it would on any device running an OS below Marshmallow

Nourdine Alouane
  • 804
  • 12
  • 22
1

I cleared the cache for whichever application I was using to try and share out the picture (Pixlr) and it was fine.

McKealty
  • 11
  • 1