通过应用程序发送电子邮件附件有不同的名称文件发送 [英] Email attachment send by app has different name than file that is sent
问题描述
我在写它有一个功能,它会发送一封电子邮件与特定的文件附件的Android应用程序。收到电子邮件时,这是工作,但该附件,这就是所谓的peroneal.pdf当我把它连接到电子邮件,(如意图,我敢肯定的是,其中的问题是)变为2131034113.pdf 。我如何改变它,这样收到的文件有原来的名字?是否有命名的意图呢?如果是这样,我怎么做呢?在此先感谢您的帮助,我重视的code片断:
意向书I =新意图(Intent.ACTION_SEND);
i.setType(信息/ RFC822);
i.putExtra(Intent.EXTRA_EMAIL,新的String [] {value.toString()});
i.putExtra(Intent.EXTRA_SUBJECT,肌腱电子邮件);
i.putExtra(Intent.EXTRA_TEXT的信息连接,只需点击发送。);
字符串rawFolderPath =android.resource://+ getPackageName()+/+ R.raw.peroneal;乌里emailUri = Uri.parse(rawFolderPath);
i.putExtra(Intent.EXTRA_STREAM,emailUri);
i.setType(应用程序/ PDF格式);
尝试{
startActivity(Intent.createChooser(我,发送邮件...));}赶上(android.content.ActivityNotFoundException前){
Toast.makeText(PTSlideShow.this,有没有安装的电子邮件客户端,Toast.LENGTH_SHORT).show();
}
这是工作,但附件,这被称为peroneal.pdf
块引用>没有,那就不叫peroneal.pdf,至少不会在设备上。
您可能对你的本地文件系统命名为
peroneal.pdf
的文件。这在很大程度上失去了,当你将其打包作为一种资源,因为你显然有。什么其他进程将看到的是
android.resource://.../2131034113
,其中2131034113
为R.raw.peroneal
的十进制值(...
是您的应用程序的软件包名)。
我如何改变它,这样收到的文档具有原来的名字?
块引用>那么,你会被它使用
乌里
,实际上有peroneal.pdf
增加你的胜算。例如,您可以复制出您的原始资源,外部存储,并使用文件
基于乌里
来代替。或者,成为了通过附件的中openFile()
基于的ContentProvider
,在这里你支持乌里
在peroneal.pdf
。但是,请记住,你问其他应用程序,以您的名义发送电子邮件。如何获得创建并打包这些电子邮件是自己与其他电子邮件应用的作者。谁也不能保证,在所有的,你的附件将根据
乌里
的最后一段被命名。的可能的有多的,将采取这种方法,但如果有,我也不会一丝惊讶电子邮件应用一些则不会。I am writing an android app which has a feature that will send an email with an attachment of a specific document. This is working but the attachment, which is called "peroneal.pdf" when I attach it to the email, (as an intent, which I'm sure is where the issue is) becomes "2131034113.pdf" when the email is received. How do I change it so that the received document has the original name? Does it have to do with naming the intent? If so, how do I do this? Thanks in advance for any help, I have attached the code snippet:
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"
No, it is not called "peroneal.pdf", at least not on the device.
You may have a file named of
peroneal.pdf
on your local filesystem. That is largely lost when you package it as a resource, as you apparently have.What the other process will see is
android.resource://.../2131034113
, where2131034113
is the decimal value ofR.raw.peroneal
(and...
is your app's package name).How do I change it so that the received document has the original name?
Well, you will increase your odds by using a
Uri
that actually hasperoneal.pdf
in it. For example, you could copy your raw resource out to external storage and use aFile
-basedUri
instead. Or, serve up the attachment via anopenFile()
-basedContentProvider
, where you support aUri
that ends inperoneal.pdf
.However, bear in mind that you are asking other apps to send email on your behalf. How those emails get created and packaged is up to the authors of those other email apps. There is no guarantee, at all, that your attachment will be named based on the last segment of the
Uri
. Probably there are many email apps that will take this approach, but I would not be the least bit surprised if there are some that will not.这篇关于通过应用程序发送电子邮件附件有不同的名称文件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!