1

I am trying to convert a Qt 5 app to Qt 6. In Qt 5 we can request Android permissions as follows:

QStringList permissions;
//...
QtAndroid::PermissionResultMap resultHash = QtAndroid::requestPermissionsSync(permissions);
for (const auto &perm : permissions)
{
    if(resultHash[perm] == QtAndroid::PermissionResult::Denied)
    {
        qDebug() << "Permission denied:" << perm;
        return false;
    }
}

What is the equivalent in Qt 6? Or is the only way to manually implement this using JNI?

Regards

Hyndrix
  • 4,282
  • 7
  • 41
  • 82

2 Answers2

1

There is no permission handling API in Qt6 yet. However, it is under making. You can follow the situation from QTBUG-90498. It looks like it is scheduled for Qt6.4 release which I assume will be due some time in the fall 2022. You can find a code review link from the bug report which might help you in writing your own implementation.

I would recommend you to take a look into QNativeInterface::QAndroidApplication::runOnAndroidMainThread which you can use for asynchronous calling on the Android UI thread.

talamaki
  • 5,324
  • 1
  • 27
  • 40
1

Here is the new Qt6 permission API (which is still under development, however can be used): QtAndroidPrivate Namespace

Example:

#include <QtCore/private/qandroidextras_p.h>

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;
}
Alexander Dyagilev
  • 1,139
  • 1
  • 15
  • 43