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

Remove file permissions, use Storage Access Framework #6

Open
bradyt opened this issue Jan 3, 2020 · 3 comments
Open

Remove file permissions, use Storage Access Framework #6

bradyt opened this issue Jan 3, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@bradyt
Copy link

bradyt commented Jan 3, 2020

I don't think this issue is a priority, but I think in the long term it is likely relevant.

I was able to use code examples at https://developer.android.com/training/data-storage/shared/documents-files to remove need for file permissions for my Android app.

I think then you could remove the following lines from App_Resources/Android/src/main/AndroidManifest.xml.

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

I'm not sure I'm reading this correctly, but it seems as soon as an app begins targeting Android 29, some of the old way of accessing files on Android will not be available. Note that ACTION_OPEN_DOCUMENT requires Android 19 but ACTION_GET_CONTENT only requires Android 16. A difference of about 3% of existing Android devices.

You could wait for one of your frameworks to implement this, I don't know if that would be NativeScript, Angular or Typescript. I've had to implement my own plugin for now, to get persistent and smooth read/write access to local files an Android.

You can see where I've implemented a custom plugin here: https://github.com/bradyt/cone/blob/v0.2.18/uri_picker/android/src/main/java/info/tangential/uri_picker/UriPickerPlugin.java#L81-L90.

EDITS:

  1. Where I said "Android 29", I meant API 29, Android 10, etc. See https://en.wikipedia.org/wiki/Android_version_history.
  2. I misspoke about ACTION_GET_CONTENT. That apparently goes back to API 1. But the framework goes back to API 17, if I'm reading this right: https://docs.nativescript.org/core-concepts/android-runtime/requirements. So then the difference in existing devices would only be 2%, according to https://developer.android.com/about/dashboards. You could use ACTION_GET_CONTENT to support those devices, but I think the user experience would be more like importing/exporting a file.
@xuhcc
Copy link
Owner

xuhcc commented Jan 4, 2020

I'm not sure I'm reading this correctly, but it seems as soon as an app begins targeting Android 29, some of the old way of accessing files on Android will not be available.

Indeed, we had a problem with file access on Android 10. Temporary workaround was added in 69a88a3 and I reported this problem to NativeScript team: NativeScript/NativeScript#8203

@bradyt
Copy link
Author

bradyt commented Nov 8, 2021

Indeed, we had a problem with file access on Android 10. Temporary workaround was added in 69a88a3 and I reported this problem to NativeScript team: NativeScript/NativeScript#8203

That issue was closed some months ago. I'm mildly curious if their fix is enough for this app. Isn't File.read only half the issue? You'll need File.write as well?

And does their approach to fixing File.read apply towards the direction of using Storage Access Framework to avoid requiring file permissions?

Above I mentioned hacking together my own use of Storage Access Framework, but fortunately @hpoul created file_picker_writable1 and I have been using that. I believe the key idea is that they are using ACTION_OPEN_DOCUMENT at FilePickerWritableImpl.kt2. Presumably we would want a NativeScript plugin that uses something like ACTION_OPEN_DOCUMENT in its implementation.

Footnotes

  1. https://github.com/hpoul/file_picker_writable

  2. https://github.com/hpoul/file_picker_writable/blob/v2.0.1/android/src/main/kotlin/codeux/design/filepicker/file_picker_writable/FilePickerWritableImpl.kt

@xuhcc
Copy link
Owner

xuhcc commented Nov 9, 2021

I think they fixed it in NativeScript 8.0 but this release contains so many breaking changes. Some plugins don't work at all and abandoned by their maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants