尝试创建临时文件时,获取“文件的父目录不可写”。我正在使用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();
}
}
答案 0 :(得分:0)
您正尝试在存储的根目录中创建文件,而不是sd-card
tempFile.createTempFile(MakeTextDate(today), ".csv");
在编写具有外部存储完整路径的日志时创建文件。