【发布时间】:2013-05-13 19:24:43
【问题描述】:
尝试创建临时文件时出现“文件的父目录不可写”。我正在使用 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();
}
}
【问题讨论】:
-
您的虚拟设备的“SD 卡”设置是什么?
-
我不明白你的意思?
-
Eclipse -> Android 设备管理器 -> 选择运行模拟器的虚拟设备 -> 编辑 -> 您拥有创建虚拟设备时填写的设置页面。那里有 SD 卡设置。
-
谢谢,这似乎已经解决了。让它成为一个答案,这样我就可以接受它!