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. Permission Denied.... "requires that you obtain access using ACTION_OPEN_DOCUMENT", after successfully opening a folder and trying to open a file in it in android

Permission Denied.... "requires that you obtain access using ACTION_OPEN_DOCUMENT", after successfully opening a folder and trying to open a file in it in android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 3 Posters 3.8k Views
  • 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.
  • S Offline
    S Offline
    Sheep
    wrote on 27 Oct 2023, 06:40 last edited by Sheep
    #1

    Greeting

    Am able to open the folder (of which is returns the "content://com.android.externalstorage.documents/tree/..") and Qt is able to parse the folder details (numbr of files, etc), but when i try to open a specific file in the selected folder, i get this error

    W AppName:  unknown unknown java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/tree/primary%3AlibTest%2Fsoqeqwe%2Fmain.xln from pid=28151, uid=10318 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
    

    I have all persmissions set..

     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    

    ..and also dynamically invoke them before opening the folder picker dialog.

    AFAIK we have to set this (ACTION_OPEN_DOCUMENT) option on the Intent object when trying to pick a file in java, but how should i do it to all files in the folder so that i can be able to read and write to them.

    Note: This folder was manually created and all files in it are manually added to it!

    Am using the Qml FolderDialog Component to select the folder with Qt 6.5 and android kit is clang 64-v8a

    Here is my code for loading the files in selected folder

    bool importMaterialLibrary(const QString &argfolder){
     QDir folderPath(argfolder);
    
    // this is able to list all files in the folder
    auto list1 = folderPath.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
      qDebug() << "My files " << list1;
    
    // the file "main.xln" exists in the folder...hence am trying to access its  contents
      QFile mainFile(folderPath.path()+"/main.xln");
     
    // this is where the error occurs
     if (!mainFile.open(QIODevice::ReadOnly)) {
        qDebug() << "Failed to open file " << mainFile.errorString();
        return false;
      }
    // file is successfully opened...read its content
    ..... 
    }
    
    M 1 Reply Last reply 7 Jan 2024, 06:20
    1
    • S Sheep
      27 Oct 2023, 06:40

      Greeting

      Am able to open the folder (of which is returns the "content://com.android.externalstorage.documents/tree/..") and Qt is able to parse the folder details (numbr of files, etc), but when i try to open a specific file in the selected folder, i get this error

      W AppName:  unknown unknown java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.ExternalStorageProvider uri content://com.android.externalstorage.documents/tree/primary%3AlibTest%2Fsoqeqwe%2Fmain.xln from pid=28151, uid=10318 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
      

      I have all persmissions set..

       <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
          <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
      

      ..and also dynamically invoke them before opening the folder picker dialog.

      AFAIK we have to set this (ACTION_OPEN_DOCUMENT) option on the Intent object when trying to pick a file in java, but how should i do it to all files in the folder so that i can be able to read and write to them.

      Note: This folder was manually created and all files in it are manually added to it!

      Am using the Qml FolderDialog Component to select the folder with Qt 6.5 and android kit is clang 64-v8a

      Here is my code for loading the files in selected folder

      bool importMaterialLibrary(const QString &argfolder){
       QDir folderPath(argfolder);
      
      // this is able to list all files in the folder
      auto list1 = folderPath.entryInfoList(QDir::Files | QDir::NoDotAndDotDot);
        qDebug() << "My files " << list1;
      
      // the file "main.xln" exists in the folder...hence am trying to access its  contents
        QFile mainFile(folderPath.path()+"/main.xln");
       
      // this is where the error occurs
       if (!mainFile.open(QIODevice::ReadOnly)) {
          qDebug() << "Failed to open file " << mainFile.errorString();
          return false;
        }
      // file is successfully opened...read its content
      ..... 
      }
      
      M Offline
      M Offline
      Mr_Ada
      wrote on 7 Jan 2024, 06:20 last edited by
      #2

      @Sheep I would like to know if you found an answer to this question? I am at the same point in not being able to access a file in shared area.

      K 1 Reply Last reply 7 Jan 2024, 06:25
      0
      • M Mr_Ada
        7 Jan 2024, 06:20

        @Sheep I would like to know if you found an answer to this question? I am at the same point in not being able to access a file in shared area.

        K Offline
        K Offline
        Kai.
        wrote on 7 Jan 2024, 06:25 last edited by
        #3

        i found this page https://ekkesapps.wordpress.com/qt-6-cmake/android-scopedstorage-filedialog/ very helpfull. In Android > 12 there are some changes to permission things.

        M 2 Replies Last reply 7 Jan 2024, 07:05
        0
        • K Kai.
          7 Jan 2024, 06:25

          i found this page https://ekkesapps.wordpress.com/qt-6-cmake/android-scopedstorage-filedialog/ very helpfull. In Android > 12 there are some changes to permission things.

          M Offline
          M Offline
          Mr_Ada
          wrote on 7 Jan 2024, 07:05 last edited by Mr_Ada 1 Jul 2024, 07:15
          #4

          @Kai I'll give it a look. Thanks. This looks like some of the changes I have made already to permissions. Except for Media which I didn't know existed.

          1 Reply Last reply
          0
          • K Kai.
            7 Jan 2024, 06:25

            i found this page https://ekkesapps.wordpress.com/qt-6-cmake/android-scopedstorage-filedialog/ very helpfull. In Android > 12 there are some changes to permission things.

            M Offline
            M Offline
            Mr_Ada
            wrote on 7 Jan 2024, 08:14 last edited by
            #5

            @Kai I followed on in the description and changed my manifest and build.gradle, etc. I don't see any improvement on getting access to a snapshot on my phone.

            K 1 Reply Last reply 7 Jan 2024, 09:20
            0
            • M Mr_Ada
              7 Jan 2024, 08:14

              @Kai I followed on in the description and changed my manifest and build.gradle, etc. I don't see any improvement on getting access to a snapshot on my phone.

              K Offline
              K Offline
              Kai.
              wrote on 7 Jan 2024, 09:20 last edited by Kai. 1 Jul 2024, 09:24
              #6

              @Mr_Ada i have also runtime check :

              ...
              #include <QtCore/private/qandroidextras_p.h>
              ...
              
              #ifdef __ANDROID__
              int setupPermission(QString permission)
              {
                  auto  result = QtAndroidPrivate::checkPermission(permission);
                  if(result.result() == QtAndroidPrivate::PermissionResult::Denied){
                      QFuture<QtAndroidPrivate::PermissionResult> resultHash = QtAndroidPrivate::requestPermission(permission);
                      if(resultHash.result() == QtAndroidPrivate::PermissionResult::Denied)
                          return -1;
                  }
                  return 0;
              }
              #endif
              
              int main(int argc, char *argv[])
              {
                  QGuiApplication app(argc, argv);
              
              #ifdef __ANDROID__
                  setupPermission(QString("android.permission.CAMERA"));
                  setupPermission(QString("android.permission.READ_EXTERNAL_STORAGE"));
              #endif
              
              ...
              

              cmake :

              target_link_libraries(myapp
                PRIVATE
                Qt6::Core
                Qt6::CorePrivate
              ...
              

              on Android SDK >= 33 you have to do this with the new permissions

              1 Reply Last reply
              1

              • Login

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