0

尝试创建临时文件时出现“文件的父目录不可写”。我正在使用 Eclipse 和模拟器。我在我的清单中使用许可:

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

这是代码:

@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();
    }
}
4

1 回答 1

0

您正在尝试在存储的根目录中创建文件,而不是 sd-card

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

使用外部存储的完整路径写入日志时创建文件。

于 2013-05-18T21:35:18.583 回答