下面的我的代码以前曾经工作过。但是,最近我格式化了手机之后,它就不再起作用了。请帮助我。
设置路径的代码是:
path = Environment.getExternalStorageDirectory().getPath() + "/IMG-20190324-WA0000.jpg";
try {
m.addAttachment(path);
if(m.send()) {
Toast.makeText(context, "Email was sent successfully :)", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Email was not sent :(", Toast.LENGTH_LONG).show();
}
} catch(Exception e) {
//Toast.makeText(context, "There was a problem sending the email.", Toast.LENGTH_LONG).show();
Log.e("MailApp", "Could not send email", e);
}
我收到以下错误:
E/MailApp: Could not send email
javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.FileNotFoundException: /storage/emulated/0/IMG-20190324-WA0000.jpg: open failed: EACCES (Permission denied)
我的清单权限:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
文件位于与以前一样的确切位置,那么为什么代码无法读取它?
答案 0 :(得分:1)
我所要做的就是转到设备设置->应用程序->我的应用程序->开启存储权限。感谢@Pklumpp帮助我