Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136668

Missing API to enable standard Android permissions

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 6.9.0
    • Extras: Android
    • None
    • Android

    Description

      If you want your application to write some files to "Documents" folder under Android, you need the manifest to have WRITE_EXTERNAL_STORAGE permissions.

      However, this is not enough, if you simply try to write the Documents folder:

      #include <QApplication>
      #include <QMainWindow>
      
      #include <QLabel>
      #include <QFile>
      #include <QStandardPaths>
      
      #include <fstream>
      
      int main( int argc, char* argv[] )
      {
          QApplication app(argc, argv);
          QMainWindow frame;
      
          QString status = "";
      
          auto folder = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
          auto fileName = folder + "/file.txt";
          // create a file:
          std::fstream file;
          file.open( fileName.toStdString().c_str(), std::ios_base::out );
          file << "Hello World!" << std::endl;
          file.close();
          if (QFile(fileName).exists())
              status += "Could create new file " + fileName + "\n";
          else
              status += "Could not create new file " + fileName + "\n";
      
          frame.setCentralWidget( new QLabel(status) );
      
          frame.show();
          return app.exec();
      }
      

      It will fail to create the file....user has to manually open Android's application settings and enable storage access permissions, then file can be created next time app it executed.

      The new QPermission mechanism (implemented to fix https://bugreports.qt.io/browse/QTBUG-90498) makes it possible to grant permission for bluetooth, location, camera....but not for storage access (nor foe wake lock, vibrate, etc...only a few permissions are handled).

      There is currently no API available to grant regular permissions, like storage access, there should definitely be one. Else you can only write files to app folder and later you won't see them when you plug the device to a computer.

      For instance "camera" sample program takes pictures: but they go to the app internal folder, rather than in user's "Picture" folder. Then, you can't retrieve those pictures if you plug the device to a computer. The app folder is completely hidden and cannot be accessed, they shall be written to user's home folder (Documents, Pictures, Music...).

      Note: I'm experiencing this with Android 9.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtandroidteam Qt Android Team
              jpo38 Jean Porcherot
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes