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. Not able to write on Android 10 although the WRITE_EXTERNAL_STORAGE is granted...
Forum Updated to NodeBB v4.3 + New Features

Not able to write on Android 10 although the WRITE_EXTERNAL_STORAGE is granted...

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
8 Posts 4 Posters 1.6k Views 3 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.
  • mbruelM Offline
    mbruelM Offline
    mbruel
    wrote on last edited by
    #1

    Hi,
    I've been trying to deploy my app on a Android 10 armv8 (One plus 6) and I've an issue when trying to write files.
    I'm getting this error:

    D ClemRemote: Download path:  "/storage/emulated/0/Download"
    E ClemRemote: "the download folder is not writable..."
    

    And also when changing to the sdcard:

    E ClemRemote: New path is not writable...  "/storage/emulated/0/Download"
    E ClemRemote: New path is not writable...  "/sdcard/download"
    

    That's from this simple test:

    void ClementineRemote::updateDownloadPath(const QString &newPath)
    {
        QFileInfo fi(newPath);
        if (!fi.exists())
            qCritical() << "New path doesn't exist... " << newPath;
        else if (!fi.isDir())
            qCritical() << "New path is not a directory... " << newPath;
        else if (!fi.isWritable())
            qCritical() << "New path is not writable... " << newPath;
        else
        {
            _downloadPath = newPath;
            _settings.setValue(sSettings[Settings::downloadPath], _downloadPath);
        }
    }
    

    Any idea what could block the app to write?

    raven-worxR 1 Reply Last reply
    0
    • mbruelM mbruel

      Hi,
      I've been trying to deploy my app on a Android 10 armv8 (One plus 6) and I've an issue when trying to write files.
      I'm getting this error:

      D ClemRemote: Download path:  "/storage/emulated/0/Download"
      E ClemRemote: "the download folder is not writable..."
      

      And also when changing to the sdcard:

      E ClemRemote: New path is not writable...  "/storage/emulated/0/Download"
      E ClemRemote: New path is not writable...  "/sdcard/download"
      

      That's from this simple test:

      void ClementineRemote::updateDownloadPath(const QString &newPath)
      {
          QFileInfo fi(newPath);
          if (!fi.exists())
              qCritical() << "New path doesn't exist... " << newPath;
          else if (!fi.isDir())
              qCritical() << "New path is not a directory... " << newPath;
          else if (!fi.isWritable())
              qCritical() << "New path is not writable... " << newPath;
          else
          {
              _downloadPath = newPath;
              _settings.setValue(sSettings[Settings::downloadPath], _downloadPath);
          }
      }
      

      Any idea what could block the app to write?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @mbruel
      IIRC since Android 10 you have to request those permissions from the user (first time only).
      See https://doc.qt.io/qt-5/qtandroid.html#requestPermissions

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • mbruelM Offline
        mbruelM Offline
        mbruel
        wrote on last edited by
        #3

        @raven-worx which permissions?
        I've already requested WRITE_EXTERNAL_STORAGE and get it granted. So I don't understand why I'm not able to write a file...
        I've done this: (cf here)

        #if defined(Q_OS_ANDROID)
                _downloadPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
                QtAndroid::PermissionResultMap res = QtAndroid::requestPermissionsSync({"android.permission.WRITE_EXTERNAL_STORAGE"});
                if (res["android.permission.WRITE_EXTERNAL_STORAGE"] != QtAndroid::PermissionResult::Granted)
                    return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
        

        And I'm not returning.
        If I check on the device the permission granted for my app, I can see it has Storage.
        Do I need other permissions?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Did you check that the folder exists ?
          If memory serves well, the directory path is valid in the sense that if follows the platform guidelines but it will not exist until you create it as it would not make any sense to "pre-create" them for all applications you install on a device.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • mbruelM Offline
            mbruelM Offline
            mbruel
            wrote on last edited by
            #5

            @SGaist yes the folders exist. it passes if (!fi.exists()) then else if (!fi.isDir()) and then fail on else if (!fi.isWritable())
            I don't understand why...
            I've only seen this issue on my friend's device, I didn't have feedback on others yet...
            But I'd like to make it work properly on any device...

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I don't remember if it's still possible be some of these cards could be physically locked for writing like the good old floppy drive. Could it be that ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • mbruelM Offline
                mbruelM Offline
                mbruel
                wrote on last edited by
                #7

                well I doubt it cause the app is neither able to write on the phone ram nor on the external sd card.
                and he's able to use his phone normally with other apps, like taking pictures...

                1 Reply Last reply
                0
                • ekkescornerE Offline
                  ekkescornerE Offline
                  ekkescorner
                  Qt Champions 2016
                  wrote on last edited by
                  #8

                  this should only be done on API Level 30, but have you tried in your manifest - application to set

                  android:requestLegacyExternalStorage="true"
                  

                  ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                  5.15 --> 6.9 https://t1p.de/ekkeChecklist
                  QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                  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