Reputation: 4452
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
Upvotes: 1
Views: 4098
Reputation: 1425
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;
}
Upvotes: 1
Reputation: 5482
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.
Upvotes: 2