如何为ACTION_SEND指定文件名? [英] How to specify filename for ACTION_SEND?
问题描述
我使用ACTION_SEND在我的应用程序发送来自内容提供商的文件作为电子邮件附件在Gmail中。这个伟大的工程,但我不能以编程指定附件的文件名。当我的URI是
内容://my.documentcontentprovider/321
附件的文件名是321 321是文档ID。
我看了看规范的意图,并没有看到EXTRA_键指定文件名。唯一的解决办法我能想出是追加文件名给我的网址:
内容://my.documentcontentprovider/321/photo.jpg
它应该工作,但似乎有点哈克。如果有人有一个更好的想法,请附和这里是我的code,在情况下,它是非常有用的:
意图sendDoc =新意图();
sendDoc.setAction(Intent.ACTION_SEND);
sendDoc.putExtra(Intent.EXTRA_SUBJECT,doc.name);
sendDoc.putExtra(Intent.EXTRA_STREAM,DocumentContentProvider.getUri(doc.id));
sendDoc.setType(doc.contentType);
this.foldersFragment.startActivity(sendDoc);
您将需要通过文件路径为 Intent.EXTRA_STREAM
。精心设计的ContentProviders暴露了 _DATA
列文件路径。
I'm using ACTION_SEND to send a file from the content provider in my app as an email attachment in GMail. This works great, except that I can't programmatically specify the filename of the attachment. When my URI is
content://my.documentcontentprovider/321
The filename of the attachment is 321. 321 is the document id.
I looked at the spec for Intent, and don't see an EXTRA_ key for specifying the filename. The only workaround I could come up with is to append the filename to my URI:
content://my.documentcontentprovider/321/photo.jpg
It should work, but it seems a little hacky. If someone has a better idea, please chime in. Here's my code, in case it's useful:
Intent sendDoc = new Intent();
sendDoc.setAction(Intent.ACTION_SEND);
sendDoc.putExtra(Intent.EXTRA_SUBJECT, doc.name);
sendDoc.putExtra(Intent.EXTRA_STREAM, DocumentContentProvider.getUri(doc.id));
sendDoc.setType(doc.contentType);
this.foldersFragment.startActivity(sendDoc);
You'll need to pass the filepath as Intent.EXTRA_STREAM
. Well-designed ContentProviders expose filepaths in the _DATA
columns.
这篇关于如何为ACTION_SEND指定文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!