【发布时间】:2019-01-21 08:53:00
【问题描述】:
我的代码中有位图,我需要通过电子邮件将其作为附件发送。
我将其保存为文件并发出发送意图,但每次出现错误(找不到文件)。
这是我的代码。
保存文件:
private void savePicture(String filename, Bitmap b, Context ctx) {
try {
FileOutputStream out;
out = ctx.openFileOutput(filename, Context.MODE_APPEND);
b.compress(Bitmap.CompressFormat.JPEG, 40, out);
if (b.compress(Bitmap.CompressFormat.JPEG, 40, out) == true) {
Toast.makeText(act,"file created",Toast.LENGTH_LONG).show();
out.close();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(act,e.getMessage(),Toast.LENGTH_LONG).show();
}
}
发送电子邮件:
public void sendmail (String filename){
String path = Environment.getExternalStorageDirectory().toString();
File file = new File(path,filename+".JPEG");
Uri pngUri = Uri.fromFile(file);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri);
startActivity(Intent.createChooser(emailIntent,"send quotation"));
}
【问题讨论】:
-
您不是要附加位图文件,而是要附加 jpg 文件。
-
什么时候找不到那个文件的错误?还有谁?
-
您正在将文件保存到应用程序的内存中。并告诉电子邮件应用程序它在外部存储器中。完全不同的parhs。
标签: android email android-intent bitmap attachment