简体   繁体   English

从Gmail上的附件获取文件路径

[英]Get the file path from attachment on Gmail

I´m trying to get a csv file from an email attachment , the idea is that when user selects the attachment an option to open with my app will appear . 我正在尝试从电子邮件附件中获取一个csv文件,其想法是当用户选择附件时,将出现一个用我的应用程序打开的选项。 I need to know the best way to get the file path from the attachment . 我需要知道从附件获取文件路径的最佳方法。

Thanks in advance. 提前致谢。

There is not necessarily a "file path" for the attachment. 附件不一定有“文件路径”。

If you have an activity set up to view files of the proper MIME type, and the user chooses to use your activity to view the email attachment, you will get a Uri to that attachment in getIntent().getData() . 如果您设置了一个活动来查看正确的MIME类型的文件,并且用户选择使用您的活动来查看电子邮件附件,则将在getIntent().getData()获得该附件的Uri That Uri may be a file:/// Uri . Uri 可能file:/// Uri It may be something else. 可能还有别的东西。 In particular, for Gmail, it will be a content:// Uri . 特别是对于Gmail,它将是content:// Uri Use a ContentResolver and openInputStream() to read in the contents pointed to by that content:// Uri . 使用ContentResolveropenInputStream()读取该content:// Uri指向的content://

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM