0

Getting "Parent directory of file is not writable" when trying to create a temp file. I am using Eclipse and the emulator. I am using the permission in my Manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Here is the code:

@SuppressWarnings("static-access")
public void sendEmail() {
    Calendar today = new GregorianCalendar();
    Log.d(TAG, "Path:" + Environment
            .getExternalStorageDirectory().getAbsolutePath()
            + "/GPSTracking/" + MakeTextDate(today) + ".csv");
    File tempFile = null;
    try { 

        tempFile.createTempFile(MakeTextDate(today), ".csv");
        FileWriter out = FormatEmail(tempFile);
    }
    catch (IOException e) { 
        // error
        Log.d(TAG, "create temp file:" + e.toString());
    }

    try {
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "Trip report");
        emailIntent
                .putExtra(Intent.EXTRA_TEXT, "Here is your Trips Report");

        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(tempFile));
        emailIntent.setType("plain/text");
        startActivity(Intent.createChooser(emailIntent, "Send email..."));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106

1 Answers1

0

You're trying to create file in root directory of storage, not sd-card

tempFile.createTempFile(MakeTextDate(today), ".csv");

Create file as you writing log with full path to external storage.

Viacheslav
  • 5,443
  • 1
  • 29
  • 36
  • I didn't understand what you are trying to say. I tried adding Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + MakeTextDate(today), ".csv" and now it says that that directory does not exist: /sdcard/sdcard/5-18-2013.csv – Kristy Welsh May 18 '13 at 21:41
  • Indeed, you seem to construct a nice path to log, but nor for the actual file... And even with that, you'll have to make sure you create the GPSTracking directory if it doesn't already exist. And of course you need external storage permission in the Manifest. – Chris Stratton May 19 '13 at 04:11