Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filename when saving a shared file #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tom93
Copy link
Contributor

@tom93 tom93 commented Apr 20, 2024

From the commit message:

Previously, the code used the last path component of the content URI, but that isn't necessarily the filename -- it can be a numeric ID.

Switch to the helper function getFilenameFromContentUri(), which uses ContentResolver to read the DISPLAY_NAME column. (If that fails, we fall back to the last component of the content URI as before, because we don't have anything better to use.)

Also improve the way the MIME type is determined. Previously it was just based on the file extension. Switch to first query the ContentResolver, then try the type of the Intent (which is supposed to be set to the MIME type of the data for ACTION_SEND, but may be set to "/" if the type is unknown), and only then fall back to using the file extension.

What is it?

  • Bugfix
  • Feature
  • Codebase improvement

Description of the changes in your PR

  • Fix filename when saving a shared file
  • Improve the way the MIME type is determined

Testing

Tested on Android 8.1 and Android 14, sharing both using Fossify File Manager and using the native Files app.

For testing, see the branch 'build/fix-filename-from-sharing-debug' of my fork (commit), which logs all the values of interest (search for lines containing "XXX" in the logcat).

Fixes the following issue(s)

Acknowledgement

Previously, the code used the last path component of the content URI,
but that isn't necessarily the filename -- it can be a numeric ID.

Switch to the helper function getFilenameFromContentUri(), which uses
ContentResolver to read the DISPLAY_NAME column. (If that fails, we
fall back to the last component of the content URI as before, because
we don't have anything better to use.)

Also improve the way the MIME type is determined. Previously it was
just based on the file extension. Switch to first query the
ContentResolver, then try the type of the Intent (which is supposed to
be set to the MIME type of the data for ACTION_SEND, but may be set to
"*/*" if the type is unknown), and only then fall back to using the
file extension.

Fixes FossifyOrg#37.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving a file to storage by sharing it causes loss of file name and extension
1 participant