I don't want my app to require any permissions, but I want the user to be able to select a file for reading. My app doesn't need arbitrary access to the filesystem. However, all openfiledialog implementations I have researched so far seem to assume permission to access external storage.
One workaround I can think of is to configure my app to be among the list of apps to open a certain type of file. I haven't tried this, but I hope this would work without permission to access external storage. However, user guidance would be less then ideal in this case. I would prefer a solution with a dialog and have the user pick the file.
I think this requirement does not undermine security, because the user has full control over the file my app can read. Is this possible somehow?
However, all openfiledialog implementations I have researched so far seem to assume permission to access external storage.
Set your minSdkVersion
to 19, then use ACTION_OPEN_DOCUMENT
, part of the Storage Access Framework.
Or, if you need your minSdKVersion
to be below 19, use ACTION_GET_CONTENT
on the older devices.
You will get a Uri
back via onActivityResult()
. Use a ContentResolver
and methods like openInputStream()
to consume the content identified by that Uri
.
I haven't tried this, but I hope this would work without permission to access external storage
Only if you exclude file:
Uri
values. For example, an <intent-filter>
that supports only content:
Uri
values would work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With