0

The issue I am having could be a hardware-related. In any case I'm stumped.

I have written some code (that I took and modified from: Writing Text File to SD Card fails) I've put the code below. It works fine on my Sony Ericcson X8. However, on the Sony Ericsson Arc, I can't find the file when I look for it on the phone! I went line by line through the code and there are no failures. It's as if it's on the phone and I'm just blind. I can even see in the debugger that the value of gpxfile is:

/mnt/sdcard/MyCompany/MyLog But when I use windows explorer to look for the file, I certainly don't see the directory MyCompany. Is there some setting on the phone that (silently) prevents writing to the SD Card?

Here is the code:

public static boolean generateNoteOnSD(String sFileName, String sBody) {
    try {
        String auxSDCardStatus = Environment.getExternalStorageState() ;
        if (!auxSDCardStatus.equals(Environment.MEDIA_MOUNTED)) {
            Log.i(TAG, "generateNoteOnSD auxSDCardSTatus: " + auxSDCardStatus);
        }

        if (auxSDCardStatus.equals(Environment.MEDIA_MOUNTED)) {
            File root = new File(Environment.getExternalStorageDirectory(), "Dexcom");
            if (!root.exists()) {
                root.mkdirs();
            }
            File gpxfile = new File(root, sFileName);
            FileWriter writer = new FileWriter(gpxfile, true);
            String currentTimeString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());

            writer.append(currentTimeString + ", " + sBody +System.getProperty("line.separator") );

           //writer.newLine();
            writer.flush();
            writer.close();
            Log.d(TAG,"generateNoteOnSD: Saved to file: " + sBody);
            return true;
        } else {
            return false;
        }
    } catch(IOException e) {
         e.printStackTrace();
         return false;
         //importError = e.getMessage();
         //iError();
    }

}

Community
  • 1
  • 1
Dave
  • 8,095
  • 14
  • 56
  • 99

1 Answers1

1

In my case the problem was that I had the Xperia ARC attached to the laptop with a USB cable. Apparently, things don't work quite right if you do that. No problem with the X8, so I'm guessing that it's phone specific. Computer may be putting lock on the file thus preventing Android from updating file. Not sure why I don't get an error though. Bottom line for future readers: Try disconnecting phone from computer.

Dave
  • 8,095
  • 14
  • 56
  • 99