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
-
wrote on 27 Oct 2023, 06:40 last edited by Sheep
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 ..... }
-
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 ..... }
-
@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.
wrote on 7 Jan 2024, 06:25 last edited byi 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.
-
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.
wrote on 7 Jan 2024, 07:05 last edited by Mr_Ada 1 Jul 2024, 07:15@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.
-
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.
wrote on 7 Jan 2024, 08:14 last edited by@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.
-
@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.
wrote on 7 Jan 2024, 09:20 last edited by Kai. 1 Jul 2024, 09:24@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