How to get file name and extension when opening email attachments

I created an intent filter to associate my activity with a custom file extension. This works fine: the mail application launches my activity for an attachment with a user extension.

In the exercise, I read the intention like this:

Uri uri = getIntent().getData(); 

and I can open the input stream OK, but I would like to know the file name and extension for the attachment. Any way to get this from Uri?

I tried to get this information with a cursor, but the mail application seems to have only two columns: _id and _data, and not something that might be related to the file name and / or extension.

I know that I can’t access the actual file, but I need to know the file name.

+4
source share
1 answer

If you execute a query with a given Uri, the cursor has 4 columns: _id , _data , _display_name and _size . _display_name is the name of the file with the extension.

Source: AOSP Email app

AttachmentUtilities.Columns - Columns used when requesting a Uri attachment

AttachmentProvider - Implementing an Attachment Provider

0
source

Source: https://habr.com/ru/post/1397618/


All Articles