Hi,

I am making a C++ Qt (Qt6.9.0) application for Linux, and I am calling:

QString folderPath = QFileDialog::getExistingDirectory(this, "Select Folder");

The dialog appears, but there appears the message: "Can't use this folder. To protect your privacy, choose another folder". I am trying to use the root of the internal storage and the root of the SD card.

The following permissions are granted on the app:

D/default : Permissions found: 6
D/default : Permission: "android.permission.ACCESS_NETWORK_STATE"
D/default : Permission: "android.permission.INTERNET"
D/default : Permission: "android.permission.MANAGE_EXTERNAL_STORAGE"
D/default : Permission: "android.permission.READ_EXTERNAL_STORAGE"
D/default : Permission: "android.permission.WRITE_EXTERNAL_STORAGE"
D/default : Permission: "org.qtproject.example.uiarchivos.DYNAMIC_RECEIVER _NOT_EXPORTED_PERMISSION"

I configured the ones for the storage in the CMakeLists.txt file:

....
# Define Android permissions
set_property(TARGET androidBrowser PROPERTY QT_ANDROID_PERMISSIONS
"android.permission.READ_EXTERNAL_STORAGE"
"android.permission.WRITE_EXTERNAL_STORAGE"
"android.permission.MANAGE_EXTERNAL_STORAGE"
)
.....

In main.cpp I do:

int main(int argc, char *argv[]) {
QApplication app(argc, argv);
requestPermissions(); // does nothing unless it is Android.
....etc, code to print the permissions that I got and code for my aplication...
return app.exec();
}

With requestPermissions as follows:

void requestPermissions()
{
#ifdef Q_OS_ANDROID
QJniObject activity = QNativeInterface::QAndroidApplication::context();
QJniEnvironment env;

QStringList permissions = {
"android.permission.READ_EXTERNAL_STORAGE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"android.permission.MANAGE_EXTERNAL_STORAGE"
};

jclass stringClass = env->FindClass("java/lang/String");
jobjectArray jPermissions = env->NewObjectArray(permissions.size(), stringClass, nullptr);

for (int i = 0; i < permissions.size(); ++i) {
QJniObject jstr = QJniObject::fromString(permissions[i]);
env->SetObjectArrayElement(jPermissions, i, jstr.object<jstring>());
}

QJniObject::callStaticMethod<void>(
"androidx/core/app/ActivityCompat",
"requestPermissions",
"(Landroid/app/Activity;[Ljava/lang/String;I)V",
activity.object<jobject>(),
jPermissions,
1
);
#endif
}

In addition, in the android emulator, I go to settings->Apps->[my applicatioin]->Permissions files and media->Files and Media and selected Allow management of all files.

So, what can I do? Is there something that I am missing? Why can't I select those folders?

I have seen QCoreApplication::requestPermission() API, but there is no permission for storage.

Thank you in advance,

Carlos