0

Say if I have filename 1234567.png on the internal filesystem - say I want to send it to the user with a share intent as CoolPicture.png - ie subclass fileprovider and replace the query method.

Is using a matrix cursor based on the cursor from super a good plan?

It seems like DISPLAY_NAME and SIZE are the only columns but doesn't seem to confirm if SIZE is int or string.

I'll plan to post my code after I answer it, I just wanted to get an idea of best practice, and perhaps contribute. Thanks

etienne
  • 3,146
  • 1
  • 24
  • 45
nAndroid
  • 862
  • 1
  • 10
  • 25

2 Answers2

1

Is using a matrix cursor based on the cursor from super a good plan?

You could do that, and it's probably OK. After all, FileProvider itself uses a MatrixCursor.

To modify an existing Cursor, I use CursorWrapper myself, in my LegacyCompatCursorWrapper, then in query() wrap the Cursor I get from the base ContentProvider implementation (e.g., FileProvider) in my wrapper.

It seems like DISPLAY_NAME and SIZE re the only columns but doesn't seem to confirm if SIZE is int or string.

That's one of the reasons I went with the CursorWrapper, to avoid messing with any existing values.

That being said, the existing FileProvider implementation uses a Long (file.length(), auto-boxed).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

This is an old question, but the new androidx.core.content.FileProvider has now a second getUriForFile method with an additional displayName param which sets the value for the OpenableColumns#DISPLAY_NAME key-column.

mathew11
  • 3,382
  • 3
  • 25
  • 32