Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Android 11 - Access legacy storage location
Forum Updated to NodeBB v4.3 + New Features

Android 11 - Access legacy storage location

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 4 Posters 3.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bernerdad
    wrote on last edited by
    #1

    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!

    M 1 Reply Last reply
    1
    • B bernerdad

      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!

      M Offline
      M Offline
      mvuori
      wrote on last edited by
      #2

      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

      A 1 Reply Last reply
      0
      • L Offline
        L Offline
        LiaoXuewei
        wrote on last edited by
        #3

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

        L 1 Reply Last reply
        0
        • L LiaoXuewei

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

          L Offline
          L Offline
          LiaoXuewei
          wrote on last edited by
          #4

          @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");

          1 Reply Last reply
          0
          • M mvuori

            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

            A Offline
            A Offline
            antoinnneee
            wrote on last edited by
            #5

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

            L 1 Reply Last reply
            0
            • A antoinnneee

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

              L Offline
              L Offline
              LiaoXuewei
              wrote on last edited by
              #6

              @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."?

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved