我最近换了电脑,所以不得不重新安装 ADT。从那以后,我一直在虚拟设备中收到此错误。
日志猫:
04-13 07:50:00.232: E/MailApp(2000): Could not send email
04-13 07:50:00.232: E/MailApp(2000): javax.mail.MessagingException: IOException while sending message;
04-13 07:50:00.232: E/MailApp(2000): nested exception is:
04-13 07:50:00.232: E/MailApp(2000): java.io.FileNotFoundException: /mnt/sdcard/csvname.csv: open failed: EACCES (Permission denied)
04-13 07:50:00.232: E/MailApp(2000): at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:676)
04-13 07:50:00.232: E/MailApp(2000): at javax.mail.Transport.send0(Transport.java:189)
04-13 07:50:00.232: E/MailApp(2000): at javax.mail.Transport.send(Transport.java:118)
04-13 07:50:00.232: E/MailApp(2000): at com.example.blueharvest.Mail.send(Mail.java:125)
04-13 07:50:00.232: E/MailApp(2000): at com.example.blueharvest.ChargeActivity$6.onClick(ChargeActivity.java:213)
04-13 07:50:00.232: E/MailApp(2000): at android.view.View.performClick(View.java:4204)
04-13 07:50:00.232: E/MailApp(2000): at android.view.View$PerformClick.run(View.java:17355)
04-13 07:50:00.232: E/MailApp(2000): at android.os.Handler.handleCallback(Handler.java:725)
04-13 07:50:00.232: E/MailApp(2000): at android.os.Handler.dispatchMessage(Handler.java:92)
04-13 07:50:00.232: E/MailApp(2000): at android.os.Looper.loop(Looper.java:137)
04-13 07:50:00.232: E/MailApp(2000): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-13 07:50:00.232: E/MailApp(2000): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 07:50:00.232: E/MailApp(2000): at java.lang.reflect.Method.invoke(Method.java:511)
04-13 07:50:00.232: E/MailApp(2000): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-13 07:50:00.232: E/MailApp(2000): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-13 07:50:00.232: E/MailApp(2000): at dalvik.system.NativeStart.main(Native Method)
04-13 07:50:00.232: E/MailApp(2000): Caused by: java.io.FileNotFoundException: /mnt/sdcard/csvname.csv: open failed: EACCES (Permission denied)
04-13 07:50:00.232: E/MailApp(2000): at libcore.io.IoBridge.open(IoBridge.java:416)
04-13 07:50:00.232: E/MailApp(2000): at java.io.FileInputStream.<init>(FileInputStream.java:78)
04-13 07:50:00.232: E/MailApp(2000): at javax.activation.FileDataSource.getInputStream(FileDataSource.java:110)
04-13 07:50:00.232: E/MailApp(2000): at javax.activation.DataHandler.writeTo(DataHandler.java:318)
04-13 07:50:00.232: E/MailApp(2000): at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1403)
04-13 07:50:00.232: E/MailApp(2000): at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:874)
04-13 07:50:00.232: E/MailApp(2000): at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:444)
04-13 07:50:00.232: E/MailApp(2000): at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:102)
04-13 07:50:00.232: E/MailApp(2000): at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:897)
04-13 07:50:00.232: E/MailApp(2000): at javax.activation.DataHandler.writeTo(DataHandler.java:330)
04-13 07:50:00.232: E/MailApp(2000): at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1403)
04-13 07:50:00.232: E/MailApp(2000): at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1745)
04-13 07:50:00.232: E/MailApp(2000): at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:636)
04-13 07:50:00.232: E/MailApp(2000): ... 15 more
04-13 07:50:00.232: E/MailApp(2000): Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
04-13 07:50:00.232: E/MailApp(2000): at libcore.io.Posix.open(Native Method)
04-13 07:50:00.232: E/MailApp(2000): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
04-13 07:50:00.232: E/MailApp(2000): at libcore.io.IoBridge.open(IoBridge.java:400)
04-13 07:50:00.232: E/MailApp(2000): ... 27 more
显现:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
代码:
public void exportDb(Context context) {
SQLiteDatabase _db = this.getReadableDatabase();
//File exportDir = new File(Environment.getExternalStorageDirectory().getPath(), "");
File exportDir = getDir(context);
if (!exportDir.exists())
{
exportDir.mkdirs();
}
File file = new File(exportDir, "csvname.csv");
try
{
file.createNewFile();
CSVWriter csvWrite = new CSVWriter(new FileWriter(file));
SQLiteDatabase db = this.getReadableDatabase();
Cursor curCSV = db.rawQuery("SELECT * FROM chrgData",null);
csvWrite.writeNext(curCSV.getColumnNames());
while(curCSV.moveToNext())
{
//Which column you want to export
String arrStr[] ={curCSV.getString(0),curCSV.getString(1), curCSV.getString(2), curCSV.getString(3), curCSV.getString(4)};
csvWrite.writeNext(arrStr);
}
csvWrite.close();
curCSV.close();
}
catch(Exception sqlEx)
{
Log.e("MainActivity", sqlEx.getMessage(), sqlEx);
}
_db.close();
}
public File getDir(Context context) {
File exportDir;
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {
exportDir = new File(android.os.Environment.getExternalStorageDirectory(),"");
} else {
exportDir = context.getCacheDir();
}
return exportDir;
}
任何和所有的帮助将不胜感激,如果需要任何其他信息,请告诉我。
提前致谢,
布拉德。