Search code examples
filedata-storageandroid

Internal Storage on HTC Desire


I'm trying to save a file to internal storage (not SD Card). As the documentation points out, if I use getExternalStorageDirectory(), the data will be placed under /Android/data/<package_name>/, but there's nothing there. This code is taken from here. Similar code worked on Archos, though.

File path = Environment.getExternalStorageDirectory();
File file = new File(path, "DemoPicture.jpg");
txtList.append(file.getPath());

try {
    path.mkdirs();
    InputStream is = getResources().openRawResource(R.drawable.icon);
    OutputStream os = new FileOutputStream(file);
    byte[] data = new byte[is.available()];
    is.read(data);
    os.write(data);
    is.close();
    os.close();
} catch (IOException e) {
    Log.d("ExternalStorage", "Error writing " + file, e);
}

I use Android SDK 2.1. Permission WRITE_EXTERNAL_STORAGEis already added in the manifest. No error in logcat. Any hint?


Solution

  • Forgot to update. The problem disappears when I simply unplug the device and run the app. A friend told me he got the same problem and solved it by closing any apps that are likely to access the SD card, e.g. Windows Explorer.