I am trying to dump some output for an app onto the SD such that it can be accessed by the user via usb. Simple enough, right? So, this is what I tried.
File sdCard = Environment.getExternalStorageDirectory();
File dirExt = new File (sdCard.getAbsolutePath() + "/dir1/dir2");
dirExt.mkdirs();
File fileExt = new File(dirExt, "filename");
Log.d("FILE", "Is directory: "+sdCard.isDirectory()+". Exists: "+sdCard.exists()
+". Can read: "+sdCard.canRead());
Log.d("FILE", "Is directory: "+dirExt.isDirectory()+". Exists: "+dirExt.exists()
+". Can read: "+dirExt.canRead());
Log.d("FILE", "Is file: "+fileExt.isFile()+". Exists: "+fileExt.exists()
+". Can read: "+fileExt.canRead());
String string = "Hello!";
try{
FileOutputStream fos = new FileOutputStream(fileExt);
fos.write(string.getBytes());
fos.close();
}catch (Exception e){
Log.e("FILE", "catch", e);
}
I also included the write permission in the manifest file and checked the sd state from environment, it said "mounted". So, we should be good to go. However, somehow I don't have access to anything on the sd directory, as explained by the logs:
4085-4085/com.my.class D/FILE: Is directory: true. Exists: true. Can read: false
4085-4085/com.my.class D/FILE: Is directory: false. Exists: false. Can read: false
4085-4085/com.my.class D/FILE: Is file: false. Exists: false. Can read: false
Is it possible to write anything on the sd-card at all? I am using an emulator with 200 MB SD storage.