尝试创建临时文件时出现“文件的父目录不可写”。我正在使用 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();
}
}