3

I am trying to save a file out from within my app to the external storage of a device. Specifically, I am trying to save a sound out.

I've followed every 'tutorial' on doing this, and none of it seemed particularly confusing to me, yet it just will not work for me. No file is ever created on the SD card at all, much less actually transferring over the information.

I've assumed I am somehow not getting the correct path to the card, but no matter what I have tried it doesn't work. I have tried entering just "/sdcard/", as well as using the getExternalStorageDirectory() method, among other random experiments.

After spending over half the day on something that would seem so trivial I can't even think straight anymore, so I hope you will excuse some of the lack of detail I'm providing, but any suggestion would be helpful at this point.

Archaos
  • 31
  • 1
  • 1
  • 2
  • possible duplicate of [Permission to write to the SD card](http://stackoverflow.com/questions/2121833/permission-to-write-to-the-sd-card) – Daniel A. White Feb 03 '11 at 01:27
  • Have you tried to save it to the Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC). On 2.2 and higher devices it is Music folder on SD card. – Zelimir Feb 03 '11 at 07:09
  • I am using a Droid X on 2.2.1 as my test device and I don't have a Music folder on my SD. Also, when I use the method you suggested it tries to use the path /mnt/sdcard/Music. Is that /mnt/ supposed to be there? I thought it was supposed to start with /sdcard/. I did try hard coding it to be sdcard/Music, and even tried using the file(path).mkdirs() to see if it would create the directories, but nothing seemed to change at all. – Archaos Feb 03 '11 at 17:48

2 Answers2

6

Are you absolutely certain the file isn't being saved to the SD card? I thought I was having the same problem. It turned out that I was saving correctly to the SD card the whole time, but the gallery wasn't being refreshed to show the files I had just saved. Use Astro File Manager to make sure the file isn't already being saved to the card. If this is the problem, add this line to refresh the gallery:

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"
                + Environment.getExternalStorageDirectory())));
Mike Ortiz
  • 4,031
  • 4
  • 27
  • 54
3

This answer should help: Permission to write on SD card android . Don't forget that you need to declare in your Android.xml file <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Community
  • 1
  • 1
I82Much
  • 26,901
  • 13
  • 88
  • 119