How to specify filename for ACTION_SEND?

狂风中的少年 提交于 2019-12-31 03:12:09

问题


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);

回答1:


You'll need to pass the filepath as Intent.EXTRA_STREAM. Well-designed ContentProviders expose filepaths in the _DATA columns.



来源:https://stackoverflow.com/questions/9089494/how-to-specify-filename-for-action-send

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!