First of all here's the code so everybody knows what we're dealing with:
try
{
// now save to external files
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
String fileName = CONSTANTS.SETTINGS.MANAGER.DEFAULT_FILE_NAME + "." + this.format.value();
File saveDir = new File(CONSTANTS.SETTINGS.MANAGER.EXTERNAL_PUBLIC_DIR + File.separator + this.projectName);
if (saveDir.mkdirs() || saveDir.isDirectory())
{
File saveFile = new File(saveDir.getAbsolutePath() + File.separator + fileName);
File saveFileRoot = new File(CONSTANTS.SETTINGS.MANAGER.EXTERNAL_PUBLIC_DIR + File.separator + "Survey-" + projectName + ".xml");
LayerManager.getInstance().setDate(new Date());
switch (format)
{
case XML:
{
if (CONSTANTS.DEBUGGING_MODE)
{
SLog.d(CONSTANTS.SETTINGS.MANAGER.LOGTAG, "Writing user file into " + saveFile.getAbsolutePath());
}
xmlSerializer.write(LayerManager.getInstance(), saveFile);
xmlSerializer.write(LayerManager.getInstance(), saveFileRoot);
}
break;
case JSON:
{
FileWriter saveWriter = new FileWriter(saveFile);
try
{
if (CONSTANTS.DEBUGGING_MODE)
{
SLog.d(CONSTANTS.SETTINGS.MANAGER.LOGTAG, "Writing user file into " + saveFile.getAbsolutePath());
}
String content = gson.toJson(LayerManager.getInstance());
saveWriter.write(content);
}
finally
{
saveWriter.flush();
saveWriter.close();
}
}
break;
default:
{
SLog.e(CONSTANTS.ACTIVITY.MAIN.LOGTAG, "No user save requested.");
}
break;
}
// send event to update media scanner
FileSaved event = new FileSaved();
EventBus.getDefault().post(event);
}
else
{
SLog.e(CONSTANTS.ACTIVITY.MAIN.LOGTAG, "Could not write into save projectName");
return false;
}
}
else
{
return false;
}
}
catch (Exception e)
{
e.printStackTrace();
}
return true;
}
This works perfectly on an android 4.1.2 device API 16.
The code creates a new diretory, named any value projectName holds, in the "external_public_dir" <= saveDir
Then, depending on format xml/json, in both cases the file is written in the newly created directory.
As a test the file is also directly written to external_public_dir.
When you attach the device to your (windows) computer the files/directories are where they should be.
However, when this code is run on a device with Android 4.4.4 API 19 the two directories are not recognized anymore by windows... .
The two 'files' test & test2 should be folders containing an xml file each. And the following makes the problem even more confusing: 1)The Android File explorer DOES recognize the directories... 2)As you can see, the other file created by saveFileRoot does appear in windows explorer...
I am stumped, any suggestions or tips would be very helpful!
Thanks in advance