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

Feature Request(Android): MediaStore API #334

Open
customautosys opened this issue Jun 5, 2022 · 5 comments
Open

Feature Request(Android): MediaStore API #334

customautosys opened this issue Jun 5, 2022 · 5 comments

Comments

@customautosys
Copy link

customautosys commented Jun 5, 2022

Hi, I was using cordova-plugin-file, but now with scoped storage it is not practical if I want to allow the user to choose where they want to save the file.

The alternative is MediaStore API, however, https://github.com/Heartade/cordova-plugin-android-mediastore allows only saving a single image to the gallery and https://github.com/a-ferrari/com-thesis-cordova-plugins-pdfstore only a single PDF file.

This should be part of core functionality as many apps need to download files to a location selected by the user.

@breautek
Copy link
Contributor

but now with scoped storage it is not practical if I want to allow the user to choose where they want to save the file.

Why isn't it practical? Scoped storage did add some restrictions, such as making the external root directory (either sdcard or emulated) an non-writable path, but apps can still write to the predefined folders such as external Pictures, Audio, etc.

You can also read files from external storage that was written by the app. Reading files written by other apps still requires the READ_EXTERNAL_STORAGE permission, which cordova-plugin-file handles.

@breautek breautek added the info-needed Further information is requested label Sep 30, 2022
@customautosys
Copy link
Author

but now with scoped storage it is not practical if I want to allow the user to choose where they want to save the file.

Why isn't it practical? Scoped storage did add some restrictions, such as making the external root directory (either sdcard or emulated) an non-writable path, but apps can still write to the predefined folders such as external Pictures, Audio, etc.

You can also read files from external storage that was written by the app. Reading files written by other apps still requires the READ_EXTERNAL_STORAGE permission, which cordova-plugin-file handles.

I created a new plugin simply because that's faster to do, https://github.com/customautosys/cordova-plugin-saf-mediastore

I think we should consider making Mediastore / SAF a core part of Cordova Android. It really is the way forward for file saving on Android.

@breautek
Copy link
Contributor

breautek commented Oct 1, 2022

It really is the way forward for file saving on Android.

That's not entirely accurate. Scoped Storage (And the MediaStore APIs) are for dealing with files that uses the External storage system on android. a Media Store plugin could be used in addition to the file plugin, but it definitely won't replace the file plugin, which can interact with both the internal filesystem as well as the external filesystem. Currently the file plugin handles this through the Direct File API. But I do understand the MediaStore is the recommended approach for interfacing with the external filesystem.

To be clear, I'm not pushing back on the MediaStore API. I'm just asking the what it provides over the File plugin or why it's not practical. For example, how were you providing UI to the user to choose where to save a file before and why doesn't that work now?

@customautosys
Copy link
Author

It really is the way forward for file saving on Android.

That's not entirely accurate. Scoped Storage (And the MediaStore APIs) are for dealing with files that uses the External storage system on android. a Media Store plugin could be used in addition to the file plugin, but it definitely won't replace the file plugin, which can interact with both the internal filesystem as well as the external filesystem. Currently the file plugin handles this through the Direct File API. But I do understand the MediaStore is the recommended approach for interfacing with the external filesystem.

To be clear, I'm not pushing back on the MediaStore API. I'm just asking the what it provides over the File plugin or why it's not practical. For example, how were you providing UI to the user to choose where to save a file before and why doesn't that work now?

I was using https://github.com/ourcodeworld/cordova-ourcodeworld-filebrowser which does not display the files in the folders disallowed by scoped storage. When you navigate to such a folder then you can't go anywhere and you're stuck and have to close the picker. That's why I had to write the MediaStore / SAF plugin.

File plugin also fails on a scoped storage device whenever you write to something that's not the app's own folder, whether in internal or external storage. So it ends up being pretty limited.

@breautek breautek changed the title No option to use MediaStore API Feature Request(Android): MediaStore API Oct 2, 2022
@breautek breautek removed the info-needed Further information is requested label Oct 2, 2022
@breautek
Copy link
Contributor

To addon...

Starting with API 33, READ_EXTERNAL_STORAGE permission is going to change and be no-op, with 3 more specific read permissions replacing it, for audio, video and images. Which I think may further promote a need for an actual MediaStore API.

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

No branches or pull requests

2 participants