最近コンピューターを変更したため、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;
}
他の情報が必要な場合はお知らせください。
前もって感謝します、
ブラッド。