My android app can't write a file to the AVD's SD card, here's the code:
File root = Environment.getExternalStorageDirectory();
Log.w("sdcard", "root.canWrite() = " + root.canWrite());
try {
File myFile = new File(root + File.pathSeparator + "mysdfile.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
myOutWriter.append("testing testing 123");
myOutWriter.close();
fOut.close();
} catch (IOException e) {
Log.w("ExternalStorage", "Error writing", e);
}
root.canWrite()
returns true, then this exception is raised:
java.io.IOException: open failed: EROFS (Read-only file system)
The manifest file has the WRITE_EXTERNAL_STORAGE permission (direct child of manifest):
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I've also tried remounting the SD card in the AVD shell using:
mount -o remount rw /mnt/sdcard
...but to no avail. The AVD also has the "SD card support" flag set. Not sure what to do from here, any ideas?
To anyone interested, the problem was that I had made an sdcard.iso image and had eclipse passing that to the AVD as the -sdcard command line argument. For whatever reason, the image was read-only. Fixed the problem by clearing the command line args and editing the AVD to start with a new sd card of size 512mb, rather than a file.