添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode . Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

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
..... 
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