我正在编写一个 Android 应用程序,它具有发送带有特定文档附件的电子邮件的功能。这是有效的,但是当我将附件附加到电子邮件时称为“peroneal.pdf”(作为 Intent ,我确定这是问题所在)在收到电子邮件时变为“2131034113.pdf” .我如何更改它以使收到的文件具有原始名称?它与命名 Intent 有关吗?如果是这样,我该怎么做?在此先感谢您的帮助,我附上了代码 fragment :
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{value.toString()});
i.putExtra(Intent.EXTRA_SUBJECT, "Tendon Email");
i.putExtra(Intent.EXTRA_TEXT , "The info is attached, just hit send.");
String rawFolderPath = "android.resource://" + getPackageName() + "/" + R.raw.peroneal;
Uri emailUri = Uri.parse(rawFolderPath);
i.putExtra(Intent.EXTRA_STREAM, emailUri);
i.setType("application/pdf");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(PTSlideShow.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
最佳答案
This is working but the attachment, which is called "peroneal.pdf"
不,它不叫“peroneal.pdf”,至少在设备上不叫。
您的本地文件系统上可能有一个名为 peroneal.pdf
的文件。当您将其打包为资源时,这在很大程度上丢失了,就像您显然拥有的那样。
其他进程将看到的是android.resource://.../2131034113
,其中2131034113
是R.raw的十进制值。 peroneal
(...
是您应用程序的包名称)。
How do I change it so that the received document has the original name?
好吧,您将通过使用实际上包含 peroneal.pdf
的 Uri
来增加您的几率。例如,您可以将原始资源复制到外部存储并改用基于 File
的 Uri
。或者,通过基于 openFile()
的 ContentProvider
提供附件,您支持以 peroneal.pdf 结尾的
。Uri
但是,请记住,您是在请求其他应用代表您发送电子邮件。如何创建和打包这些电子邮件取决于其他电子邮件应用程序的作者。根本无法保证您的附件将根据 Uri
的最后一段命名。 可能有许多电子邮件应用程序会采用这种方法,但如果有一些应用程序不会采用这种方法,我一点也不会感到惊讶。
关于android - 应用程序发送的电子邮件附件与发送的文件名称不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13298758/