tags:

views:

114

answers:

1

Hello,

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

+2  A: 

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

Loxley
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
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