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

Add writeContent #1

Merged
merged 1 commit into from
Jun 23, 2022
Merged

Conversation

jfaltis
Copy link
Contributor

@jfaltis jfaltis commented Jun 22, 2022

This PR adds the functionality to write content to a URI.

@espresso3389
Copy link
Owner

The PR does not make sense to me.
I think the plugin is to resolve the URL content but not to generate some.
Could you please explain more about your use case?

@jfaltis
Copy link
Contributor Author

jfaltis commented Jun 23, 2022

If you target Android 11 you won't be able to freely access the external storage of the Android device (https://developer.android.com/about/versions/11/privacy/storage). You will have to use the Storage Access Framework which allows the user to pick a folder in the external storage to which the app will be granted access to.

To write to a file you have to use the ContentResolver with openFileDescriptor to be able to get a reference to an OutputStream. https://developer.android.com/training/data-storage/shared/documents-files

This plugin was the only plugin I found which was related to the ContentResolver. Since you can only pass specific data types between flutter and the native code (https://docs.flutter.dev/development/platform-integration/platform-channels?tab=type-mappings-java-tab) you cannot expose the file descriptor to flutter (from my understanding). Therefore I implemented a method which just writes bytes to a file.

I totally see your point about how the ContentResolver is just responsible for resolving content. I don't know if it might be possible to expose the file descriptor and use it in dart or if this piece of code I have written is better suited for a storage access framework flutter library like https://github.com/lakscastro/shared-storage or https://github.com/ivehement/saf

@espresso3389
Copy link
Owner

OK, it's not a major usage of content provider but it may be neccesary on certain situation.

@espresso3389 espresso3389 merged commit 255812e into espresso3389:main Jun 23, 2022
@espresso3389
Copy link
Owner

0.1.0 is released now!

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.

2 participants