1

is there any way to write data to a sdcard when the card is mounted as a disc via usb?

I get an permission denied exception. If I unplug it everything is fine.

I know I should be using Environment.getExternalStorageDirectory, but I don't think this would make any difference.

Code:

        File file = new File("/sdcard/Test/test.txt");

        BufferedOutputStream buf = new BufferedOutputStream(
                 new FileOutputStream(file,true));

         buf.write(str.getBytes());

Thanks,

Nicholas

Nicholas
  • 21
  • 2

1 Answers1

5

No, there isn't. Only one OS may use the sdcard(-partition) at any time.

Loxley
  • 1,781
  • 17
  • 20
  • I agree with this answer. You could then create a broadcast receiver to be notified when the SD card is mounted in android again by using something like the code in here: http://stackoverflow.com/questions/3417161/android-intent-for-sdcard-ready – stealthcopter Aug 13 '10 at 13:30
  • Okay, thanks anyway. I realize that I will have to check if it's mounted. This thread tells how to http://stackoverflow.com/questions/902089/how-to-tell-if-the-sdcard-is-mounted-in-android – Nicholas Aug 13 '10 at 13:31