0

My app can write and delete file from the android sd card by adding the

android.permission.WRITE_EXTERNAL_STORAGE permission.

But this does not work with the external SD card some devices support. Writing to the default SD card (/mnt/sdcard0 in most cases) has no problem, but this does not work with the extra sd cards (/mnt/sdcard1 ).

I have googled about this and also gone through some threads in stackoverfolw itself, but still i am not able to find a proper solution.

Is it really a bug in android? Is there any workaround for this?

I will really appreciate any clarification on this.

Jagadesh Seeram
  • 2,630
  • 1
  • 16
  • 29
ranjan
  • 351
  • 1
  • 5
  • 16
  • 1
    Dont hardcode SDCard, use getExternalStorageDirectory () – Skynet Dec 31 '13 at 05:19
  • Try checking the state of the SD card before you attempt to write to it. It may be used as a shared drive, corrupted, full, etc. A list of states can be found here [http://developer.android.com/reference/android/os/Environment.html](http://developer.android.com/reference/android/os/Environment.html) – M D Dec 31 '13 at 05:20
  • if your os is KitKat then a Security is added from API-19: http://developer.android.com/about/versions/android-4.4.html and http://developer.android.com/reference/android/Manifest.permission.html#READ_EXTERNAL_STORAGE – Hulk Dec 31 '13 at 05:32
  • Environment.getExternalStorageDirectory() gives you the path. Try with this solution. http://stackoverflow.com/questions/5694933/find-an-external-sd-card-location/15612964#15612964 – Kalai.G Dec 31 '13 at 05:32
  • I am able to read the files for the external SD card. But the problem is I can not write or delete from this external SD card. It behaves as read only. I am able to list all the files from the external SD card. Writing files in the default SD card doesn't have any problem. – ranjan Jan 03 '14 at 13:23

1 Answers1

1

You can get the path of sdcard from this code:

String path = Environment.getExternalStorageDirectory().getAbsolutePath();

Then specify the foldername and file name.

if you are using an emulator, double-check to make sure that you have filled in a value for the SD Card size.

No_Rulz
  • 2,679
  • 1
  • 20
  • 33