gpt4 book ai didi

java - 如何发送带有 android Intent 的附件的电子邮件?

转载 作者:太空狗 更新时间:2023-10-29 16:00:07 27 4
gpt4 key购买 nike

我正在尝试发送带有附件的电子邮件。内部存储中的文件,所以这是我的代码:

File filelocation = new File(getFilesDir().getAbsolutePath()+"/MyApp", "FileName");
Uri path = Uri.fromFile(filelocation);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"mailmailmail@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));

但我总是得到:Permission denied for file

我该如何解决??

最佳答案

我是这样解决的:我将要发送的文件复制到外部缓存目录中,然后发送。

File temporaryFile = null;
try {
temporaryFile = File.createTempFile(keyType.getKeyTypeString(), ".pem", context.getExternalCacheDir() );
Utils.copy(new File(getFilesDir().getAbsolutePath()+"/"+ Utils.APP_OPERATOR_DIR, keyType.getKeyTypeString()+".pem"), temporaryFile);
} catch (IOException e) {
e.printStackTrace();
}

File filelocation = new File(getFilesDir().getAbsolutePath()+"/MyApp", "FileName");
Uri path = Uri.fromFile(filelocation);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"mailmailmail@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));

关于java - 如何发送带有 android Intent 的附件的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38234297/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com