Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Android 11 - Access legacy storage location



  • Hi Qt'ers. An older (Qt 5.12) version of our app writes its SQLite db file to the folder /sdcard/Android/data/OurCompanyName. This worked great on Android 6 through 10. After an upgrade to Android 11, the app can no longer access the db file in that folder. We get a 'permission denied' error when we try to open the file for reading. I've updated the app to Qt 5.15.1 and I am attempting to follow the Android Developer site's scoped storage recommendation of migrating the data out of the legacy folder to a folder within the app's scoped storage. The problem is that I cannot figure out how to actually copy/move the file successfully. I'm doing the following:

    • Have READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permission request in the manifest.
    • Have android:requestLegacyExternalStorage="true" in the manifest.
    • Android API target at Qt 5.15.1's default of 28. Also tried setting it to 29. It didn't help.
    • On app startup, use QtAndroid::checkPermission and QtAndroid::requestPermissionsSync to request access to external storage from the user. Confirmed in Settings->Apps that the app has the permission to 'Allow management of all files'.
    • Tried opening the db file for read-only using QFile, get 'access denied' error.
    • Tried opening the db file using Java File API. File::exists() returns true but File::canRead() returns false.

    My testing process is:

    • Roll phone back to Android 9, install old version of app and let it create its db file in the legacy storage location.
    • Let the phone update to Android 10, confirm old version of app can still open db file.
    • Let the phone update to Android 11. Old version of app can no longer open db file (access denied error).
    • Deploy new Qt 5.15.1 version of the app to the phone using Qt Creator.

    I'm now out of ideas on how to get the db file out of the legacy storage location via Qt/Java code. Any ideas would be greatly appreciated. Cheers!



  • I don't know anything about this, but apparently you can access the old storage under Android 11 if you target one step lower API and request access - hopefully someone can tell a clean way to fo this in Qt. See:

    https://developer.android.com/about/versions/11/privacy/storage



  • I have a similar problem. Can't access external storage under android 10, qt5.10. Do you know what to do?



  • @LiaoXuewei However, there are some differences. In my case, I can create a directory and copy files, but can't open the file (APK installation). Android 9 and earlier versions can use QDesktopServices::openUrl("APK file");



  • @mvuori
    I found a way to do it with qt, we just have to add flag in the manifest
    See link for détail



  • @antoinnneee said in Android 11 - Access legacy storage location:

    @mvuori
    I found a way to do it with qt, we just have to add flag in the manifest
    See link for détail
    Do you mean this "android:requestLegacyExternalStorage="true" in the manifest."?


Log in to reply