google / modernstorage

ModernStorage is a group of libraries that provide an abstraction layer over storage on Android to simplify its interactions
https://google.github.io/modernstorage/
Apache License 2.0
1.24k stars 54 forks source link

[Filesystem] Add support for Files.probeContentType #39

Closed yrezgui closed 2 years ago

yrezgui commented 3 years ago

The method Files.probeContentType doesn't seem to work with ContentPath. See documentation here

nic0lette commented 3 years ago

Can you add a stack trace or something for how this fails? I added tests (to my WIP branch) for Files.probeContentType and it worked without me adding any code, which made me suspicious.

nic0lette commented 3 years ago

Ah, I see now. It's impossible to load a custom implementation of FileTypeDetector because our detector would be in the app's APK but the system only looks in the system's classpath for the service loader data.

If the file extension matches the correct mime type it works. If it doesn't, then this method will either return the wrong values or null, unfortunately.