Skip to content

Android Shared Storage Qt Wrapper A New Qt (5.x & 6.x) Library for Complete Shared Storage Access

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.

Until we manage to add the missing pieces to Qt’s platform abstraction, or if you still need to use Qt 5.x, you can use our shared storage library.

Here you can find an example that shows how to use this library to perform most of the common operations.

Another thing that I personally don’t like about the current Qt platform abstraction is that FileDialog QML Type will add QWidgets to your pure QML application. I hope we’ll address this in the next Qt versions as well.

About KDAB

If you like this article and want to read similar material, consider subscribing via our RSS feed.

Subscribe to KDAB TV for similar informative short video content.

KDAB provides market leading software consulting and development services and training in Qt, C++ and 3D/OpenGL. Contact us.

2 thoughts on “Android Shared Storage Qt Wrapper”

  1. 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 🙂

  2. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *