Qt 6.4 and permissions
-
Hello,
I'm trying to access the Android permissions under 6.4 but it doesn't seem to work. I proceed as follows:
bool checkPermission(QString string) { auto result = QtAndroidPrivate::checkPermission(string).then([]( QtAndroidPrivate::PermissionResult result) { return result; }); result.waitForFinished(); return result.result() != QtAndroid::PermissionResult::Denied; } bool requestPermission(QString string) { auto result = QtAndroidPrivate::requestPermission(string); return result.result() != QtAndroid::PermissionResult::Denied; }
In my main.cpp, I have :
if (!checkPermission("android.permission.ACCESS_FINE_LOCATION")) requestPermission("android.permission.ACCESS_FINE_LOCATION");
In my AndroidManifest, I have:
<uses-permission android:name="com.android.vending.CHECK_LICENSE"/> <uses-permission android:name="com.android.vending.BILLING"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.CAMERA"/>
And at runtime, I hold:
W qt.positioning.android: : Position data not available due to missing permission 4
I saw that the teams are working on a permissions system for Qt 6.x (https://bugreports.qt.io/browse/QTBUG-90498)
Should we wait until it is ready or can we use a method similar to mine but that works?Thank you!
-
I can confirm the issue with permission requesting. I am porting Android application from Qt5 to Qt6 and have problems with requesting various permissions, for example for camera.
All permissions are listed in the manifest and here is the code I use to check and acquire permission
auto check = QtAndroidPrivate::checkPermission( "android.permission.CAMERA" ); if ( check.result() == QtAndroidPrivate::PermissionResult::Denied ) { auto req = QtAndroidPrivate::requestPermission( permissionString ); if ( req.result() == QtAndroidPrivate::PermissionResult::Denied ) { return false; } } return true;
In the log I see following message after calling
QtAndroidPrivate::requestPermission()
I Timeline: Timeline: Activity_launch_request time:1197901544 intent:Intent { act=android.content.pm.action.REQUEST_PERMISSIONS pkg=com.google.android.packageinstaller (has extras) } I art : Thread[3,tid=8328,WaitingInMainSignalCatcherLoop,Thread*=0x7f9e244e00,peer=0x12cd5a60,"Signal Catcher"]: reacting to signal 3
After this app freezes and needs to be killed.
Maybe this is a bug in Qt6.
-
So, it finally seems to work under Qt6. I use :
bool checkPermission(QString chaine) { auto result = QtAndroidPrivate::checkPermission(chaine).then([]( QtAndroidPrivate::PermissionResult result) { return result; }); result.waitForFinished(); return result.result() != QtAndroidPrivate::PermissionResult::Denied; } bool requestPermission(QString chaine) { auto result = QtAndroidPrivate::requestPermission(chaine).then([]( QtAndroidPrivate::PermissionResult result) { return result; }); result.waitForFinished(); return result.result() != QtAndroidPrivate::PermissionResult::Denied; }
I don't know if this is satisfactory as a method but it seems to work with Qt 6.4