Tuesday, February 7, 2012

[android-developers] Problem with writing files to internal memory (not visible on file browser on ICS)

I have a problem when I try to write a file to the device's SD-card.

It's an export in CSV format that I save to the directory /Android/
data/eu.vranckaert.worktime/files/worktime/ and the name of the file
is "export.csv" in this case.

File exportDir = ctx.getExternalFilesDir(null);
File file = new File(exportDir, "export.csv");
//Already had the issues before I was applying these
permissions!
file.setReadable(true, false);
file.setWritable(true, false);
file.setExecutable(false, false);
boolean fileAlreadyExists = file.createNewFile();
if(fileAlreadyExists) {
file.delete();
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(result.toString());
bw.close();
fw.close();

I tested this code and here are the results:
1) Emulator 2.3 with SD => no problem
2) Emulator 3.2 with SD => no problem
3) Emulator 4.0 with SD => no problem
4) HTC Hero (running 2.3.3) with SD => no problem
5) Samsung Galaxy ACE (running 2.3.x) with SD => no problem
6) Samsung Galaxy Nexus (running 4.0) with the 16 GB build-in SD =>
problem!!

The problem I have is that I cannot see the file that is created:
a. when I use a file browser on the device
b. when I connect the device to my windows computer (windows 7)

However I can see the entire directory structure created, just not the
files! I already had this problem before when I was not applying the
permissions, I just thought to try that without any luck.

But I noticed something else, when launching DDMS I can see the file
and download it from the device on my computer.
However this is not user-friendly so I want to have my export working
on ICS as well witouth any hacks for the user to access his exported
files.

I also tried to change the directory where it's saved, instead of the
"/Android/data" directory structure, I set it up to save on my SD-card
to the "/worktime/" directory, but that doesn't work either!

You can check out the DDMS and explorer screenshots I took attached to
the issue on google code: code.google.com/p/worktime/issues/detail?
id=84#c4

Does anyone know what I'm doing wrong or can do better to have this
working?

Kr,

Dirk

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment