mit-cml / appinventor-sources

MIT App Inventor Public Open Source
http://appinventor.mit.edu/appinventor-sources/
Apache License 2.0
1.5k stars 2.08k forks source link

Implement a FilePicker component using Storage Access Framework #2565

Open ewpatton opened 3 years ago

ewpatton commented 3 years ago

Describe the desired feature

Newer Android versions lock down file access. There is a Storage Access Framework that allows the user to pick a file from the file system and grant the app access to that one file (or directory). It would be good if we implemented a new FilePicker, similar to ImagePicker, that uses the Storage Access Framework to prompt users to pick files for creation/editing/deletion in an app, in compliance with the latest best practices for file access in Android 11+.

Give an example of how this feature would be used

An example app might include loading a CSV file for doing some mathematical analysis (or charting, once #1776 is merged). Picking the file from the filesystem is presently not available in core App Inventor.

Why doesn't the current App Inventor system address this use case?

Previously, one might be able to provide a path directly to a file, but newer restrictions in Android make this no longer possible. The user must give explicit access to a file outside of the app's scoped storage.

Why is this feature beneficial to App Inventor's educational mission?

The inclusion of the new component alleviates some pressure around file access in newer versions of Android, and can also serve as a launching off point to discuss access control, security best practices, etc.

sensei-z commented 3 years ago

https://github.com/google/modernstorage https://github.com/anggrayudi/SimpleStorage https://github.com/tom5079/DocumentFileX

these libraries can help but those are written in Kotlin Maybe kotlin support needed

using these we can access SAF easily

vknow360 commented 3 years ago

https://github.com/google/modernstorage https://github.com/anggrayudi/SimpleStorage https://github.com/tom5079/DocumentFileX

these libraries can help but those are written in Kotlin Maybe kotlin support needed

using these we can access SAF easily

I don't think so. Kotlin can be important only if you want to be dependent on those libraries. But according to my experience of last few weeks, it is quite easy to implement SAF with DocumentsContract, however it is complicated to understand.

ewpatton commented 3 years ago

The Storage Access Framework doesn't seem particularly hard to use to begin with. I'm not clear what these libraries will buy us except for a lot of additional dependencies that we will have to maintain backward compatibility for. In any event, we'd want to think about how to handle fallbacks for versions of Android prior to 5.0 or 4.4, which are when most of the components of SAF were introduced.

vknow360 commented 3 years ago

Yes, that's is the reason we should try to stick with official APIs and libraries. Here is an aix completely based upon DocumentsContract: https://drive.google.com/file/d/1xs88D-iuGbQg__q1ktxxR2hsH61aaQkW/view?usp=drivesdk

Working fine on Android 11. Since I was unable to test it on older versions so I have had to postpone its release.

vknow360 commented 3 years ago

Yes, that's is the reason we should try to stick with official APIs and libraries. Here is an aix completely based upon DocumentsContract: https://drive.google.com/file/d/1xs88D-iuGbQg__q1ktxxR2hsH61aaQkW/view?usp=drivesdk

Working fine on Android 11. Since I was unable to test it on older versions so I have had to postpone its release.

Fiinally I can release it now (at least as beta). https://drive.google.com/file/d/1xs88D-iuGbQg__q1ktxxR2hsH61aaQkW/view?usp=sharing