How can I get the Android read/write permission in QT6
-
bool checkPermission() { auto r = QtAndroidPrivate::checkPermission(QtAndroidPrivate::Storage).result(); if (r == QtAndroidPrivate::Denied) { r = QtAndroidPrivate::requestPermission(QtAndroidPrivate::Storage).result(); if (r == QtAndroidPrivate::Denied) return false; } return true; } This code did not working on Qt6.6.1
-
bool checkPermission() { auto r = QtAndroidPrivate::checkPermission(QtAndroidPrivate::Storage).result(); if (r == QtAndroidPrivate::Denied) { r = QtAndroidPrivate::requestPermission(QtAndroidPrivate::Storage).result(); if (r == QtAndroidPrivate::Denied) return false; } return true; } This code did not working on Qt6.6.1
Hi @rhaps29,
This code did not working on Qt6.6.1
It seems that somewhere between Qt 6.2 and 6.4, the those (preliminary) functions were changed to take permission name strings instead of the (now gone)
QtAndroidPrivate::Permission
enum.You can see how the
QtAndroidPrivate::Storage
enum label previoulsy mapped here:case QtAndroidPrivate::Storage: return {QStringLiteral("android.permission.READ_EXTERNAL_STORAGE"), QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE")};
So try using one, or both, of those, eg:
QtAndroidPrivate::checkPermission(QStringLiteral("android.permission.READ_EXTERNAL_STORAGE")).result();
Cheers.
-
Hi @rhaps29,
This code did not working on Qt6.6.1
It seems that somewhere between Qt 6.2 and 6.4, the those (preliminary) functions were changed to take permission name strings instead of the (now gone)
QtAndroidPrivate::Permission
enum.You can see how the
QtAndroidPrivate::Storage
enum label previoulsy mapped here:case QtAndroidPrivate::Storage: return {QStringLiteral("android.permission.READ_EXTERNAL_STORAGE"), QStringLiteral("android.permission.WRITE_EXTERNAL_STORAGE")};
So try using one, or both, of those, eg:
QtAndroidPrivate::checkPermission(QStringLiteral("android.permission.READ_EXTERNAL_STORAGE")).result();
Cheers.
@Paul-Colby I tried using your source code. but it also did not work
QtAndroidPrivate::checkPermission(QStringLiteral("android.permission.READ_EXTERNAL_STORAGE")).result();
-
bool checkPermission() { auto r = QtAndroidPrivate::checkPermission(QtAndroidPrivate::Storage).result(); if (r == QtAndroidPrivate::Denied) { r = QtAndroidPrivate::requestPermission(QtAndroidPrivate::Storage).result(); if (r == QtAndroidPrivate::Denied) return false; } return true; } This code did not working on Qt6.6.1
@rhaps29 the 'private' permissions code has been replaced with the public QPermission classes that actually have backwards compatibility guarantees like the rest of Qt.
https://doc.qt.io/qt-6.5/permissions.html
You probably will find documentation about what to do with 'storage' permissions.
As far as I know this is only set in the manifest and can't be requested at runtime.