In this article, I'd like to talk about Android storage.
In recent Android versions, Google decided, for a good reason, to restrict the access to the SD card. This means, even if your application will have the old READ/WRITE_EXTERNAL_STORAGE permissions declared and granted, you won't be able to freely access the SD Card contents like you used to.
In order to access the SD card or any other shared storage places, you'll have to use the Android shared storage API.
The good news is that, with this API, you'll be able to access any file from any storage location (i.e. from gdrive), without any special code.
As you probably already know, a long time ago, my colleagues added to Qt 5.13 the following basic support features for shared storage:
- create a new file using an existing content provider (i.e. QFileDialog)
- open an existing file using an existing content provider (i.e. QFileDialog)
- list directory content* using an URL from an existing content provider (i.e. QFileDialog)
But there are quite a few features that are missing, mostly due to these missing implementation or incompatible/limited Qt platform abstractions:
- create a new file in an existing folder URI.
- create a new folder in an existing folder URI.
- remove a file/folder.
- rename a file/folder.
- move a file/folder to another place.
- copy a file/folder to another place.
- get file mime type.
- etc.
We've added all the above missing features to a new Qt (5.x & 6.x) shared storage library for Android. This library gives you complete access to documents and other files from shared storage.
4 Comments
20 - Nov - 2022
Ekkehard Gentz
Hi BogDan, just found this. (was mentioned here: https://bugreports.qt.io/browse/QTBUG-98974?focusedCommentId=677732&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-677732) really cool work :) This should help to get a great workaround because of ScopedSorage problems. In one of my customers apps I have 2 scenarios: 1. Open File Dialog, Select Files, copy them into AppData, then upload contents to server and delete from AppData 2. Save a downloaded File into a Folder Seems I can do this with your SharedStorage library :)
4 - Mar - 2024
xf Gao
this lib can operate file once only, I want to write another file cannot, the file can be create, but write data is zero bytes.
12 - Nov - 2024
Alex
Hi, Is it still needed in Qt 6.8 ?
12 - Nov - 2024
BogDan Vatra
AFAIK 6.8 added a few more features, but I don't know if there are all features implemented.