views:

696

answers:

2

In the emulator I can't seem to write to the attached SDCard. The following code always spits out the "can't write root" log message, but not the "can't read root" one.

File routesRoot = Environment.getExternalStorageDirectory();
if (!routesRoot.canWrite())
    Log.v(getClass().getSimpleName(), "can't write root");
if (!routesRoot.canRead())
    Log.v(getClass().getSimpleName(), "can't read root");

Ideas?

+10  A: 

Check, and then double check that you have the WRITE_EXTERNAL_STORAGE permission.

moritz
I don't know how I missed that. Thank you.
fiXedd
It's worth mentioning that this was introduced in API level 4 (Android 1.6)... it "just worked" before that.
fiXedd
thx for the edit. just dont like links :-)
moritz
keep in mind, to err is human, to arr is pirate ...
moritz
A: 

Thanks for this. So many of the available Android books are out of date on this stuff. I thought I was losing my mind.

Crawlder
Same here. Like I said in reply to moritz's answer, it just worked before API level 4.
fiXedd