How to use QtAndroidPrivate::checkPermission ?
-
wrote on 26 Jul 2022, 09:26 last edited by
I got this far:
[code]
#include <QtCore/private/qandroidextras_p.h>..
auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE"));
[/code]
Now i need to check if it succeeded, i'm trying QtAndroidPrivate::PermissionResult::Denied but i can't find the correct way, do i need QFutureI'm wondering if it's supported at all, i'm reading all kinds of things like proper android support (permisssions) only present in a later version? Anybody know some facts?
Also i'm wondering if widgets are still supported for android, i don't see much talk about it, i can't get used to those xml thingies, sorry.
-
I got this far:
[code]
#include <QtCore/private/qandroidextras_p.h>..
auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE"));
[/code]
Now i need to check if it succeeded, i'm trying QtAndroidPrivate::PermissionResult::Denied but i can't find the correct way, do i need QFutureI'm wondering if it's supported at all, i'm reading all kinds of things like proper android support (permisssions) only present in a later version? Anybody know some facts?
Also i'm wondering if widgets are still supported for android, i don't see much talk about it, i can't get used to those xml thingies, sorry.
@JeanCremers You can see how to use QFuture here: https://doc-snapshots.qt.io/qt6-dev/qfuture.html
Something like:QFuture<QtAndroidPrivate::PermissionResult> future = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")).then([](QtAndroidPrivate::PermissionResult result) { ... });
-
wrote on 26 Jul 2022, 10:15 last edited by JeanCremers
Wow what a syntax. Thanks.
I'm using qt 6.2, maybe that's why it shows an error?
On second thought, i don't think this is correct syntax.auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")); QFuture<QtAndroidPrivate::PermissionResult> future = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")).then([]( QtAndroidPrivate::PermissionResult result) { return 0; });
main.cpp:15:45: No viable conversion from 'QFuture<ResultType<(lambda at C:/Android/pd/planetdance/main.cpp:15:147)>>' to 'QFutureQtAndroidPrivate::PermissionResult'
qfuture.h:60:7: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'QFuture<ResultType<(lambda at C:/Android/pd/planetdance/main.cpp:15:147)>>' (aka 'QFuture<int>') to 'const QFutureQtAndroidPrivate::PermissionResult &' for 1st argument
qfuture.h:60:7: candidate constructor (the implicit move constructor) not viable: no known conversion from 'QFuture<ResultType<(lambda at C:/Android/pd/planetdance/main.cpp:15:147)>>' (aka 'QFuture<int>') to 'QFutureQtAndroidPrivate::PermissionResult &&' for 1st argument
qfuture.h:71:14: explicit constructor is not a candidate
qfuture.h:76:14: explicit constructor is not a candidate
qfuture.h:82:14: explicit constructor is not a candidate -
Wow what a syntax. Thanks.
I'm using qt 6.2, maybe that's why it shows an error?
On second thought, i don't think this is correct syntax.auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")); QFuture<QtAndroidPrivate::PermissionResult> future = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")).then([]( QtAndroidPrivate::PermissionResult result) { return 0; });
main.cpp:15:45: No viable conversion from 'QFuture<ResultType<(lambda at C:/Android/pd/planetdance/main.cpp:15:147)>>' to 'QFutureQtAndroidPrivate::PermissionResult'
qfuture.h:60:7: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'QFuture<ResultType<(lambda at C:/Android/pd/planetdance/main.cpp:15:147)>>' (aka 'QFuture<int>') to 'const QFutureQtAndroidPrivate::PermissionResult &' for 1st argument
qfuture.h:60:7: candidate constructor (the implicit move constructor) not viable: no known conversion from 'QFuture<ResultType<(lambda at C:/Android/pd/planetdance/main.cpp:15:147)>>' (aka 'QFuture<int>') to 'QFutureQtAndroidPrivate::PermissionResult &&' for 1st argument
qfuture.h:71:14: explicit constructor is not a candidate
qfuture.h:76:14: explicit constructor is not a candidate
qfuture.h:82:14: explicit constructor is not a candidate@JeanCremers said in How to use QtAndroidPrivate::checkPermission ?:
auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE"));
Not needed.
Change
QFuture<QtAndroidPrivate::PermissionResult> future
to
auto future
-
wrote on 26 Jul 2022, 10:38 last edited by
Thanks for your help.
I now have a function but i can't test it yet, i'm getting strange errors, i think i'm gonna install qt anew.
bool checkPermission(void) { auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")).then([]( QtAndroidPrivate::PermissionResult) { return 0; }); return 1; }
-
Thanks for your help.
I now have a function but i can't test it yet, i'm getting strange errors, i think i'm gonna install qt anew.
bool checkPermission(void) { auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")).then([]( QtAndroidPrivate::PermissionResult) { return 0; }); return 1; }
@JeanCremers said in How to use QtAndroidPrivate::checkPermission ?:
bool checkPermission(void)
{
auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")).then( {
return 0;
});
return 1;
}This can't work.
If you want to return the result of checkPermission from checkPermission you will have to wait for the future and then check its result. Something like:bool checkPermission(void) { auto result = QtAndroidPrivate::checkPermission(QString("android.permission.WRITE_EXTERNAL_STORAGE")).then([]( QtAndroidPrivate::PermissionResult result) { return result; }); result.waitForFinished(); return result.result() != QtAndroid::PermissionResult::Denied; }
-
wrote on 26 Jul 2022, 11:19 last edited by
I'm stuck at #include <QtCore/private/qandroidextras_p.h> now, it says 'in included file, 'jni.h' not found.
Qt for android is still not very user friendly. :( -
I'm stuck at #include <QtCore/private/qandroidextras_p.h> now, it says 'in included file, 'jni.h' not found.
Qt for android is still not very user friendly. :(wrote on 26 Jul 2022, 11:30 last edited by JeanCremersI found this post, it seems we have to wait a while.. https://stackoverflow.com/questions/71216717/requesting-android-permissions-in-qt-6
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.
-
wrote on 26 Jul 2022, 13:19 last edited by
Did you add this in your pro file?
QT += androidextrasJust curious: does QtAndroidPrivate::checkPermission take long for your code to wait?
In my code, there is not waiting. Also it is better for you to add these permissions in menifest file. When it is opened in Qt Creator, you can see a group box Permissions. Add the permissions there as well. -
Did you add this in your pro file?
QT += androidextrasJust curious: does QtAndroidPrivate::checkPermission take long for your code to wait?
In my code, there is not waiting. Also it is better for you to add these permissions in menifest file. When it is opened in Qt Creator, you can see a group box Permissions. Add the permissions there as well.wrote on 26 Jul 2022, 13:34 last edited by@JoeCFD
I thought androidextras was in qt 5?At the moment i don't have a working build and plan to wait for 6.4 when there's hopefully decent permission functions.
-
@JoeCFD
I thought androidextras was in qt 5?At the moment i don't have a working build and plan to wait for 6.4 when there's hopefully decent permission functions.
wrote on 26 Jul 2022, 15:05 last edited by JoeCFD@JeanCremers True it is for 5. Things in Qt6 are different. Great: another round of learning.
-
@JeanCremers True it is for 5. Things in Qt6 are different. Great: another round of learning.
wrote on 26 Jul 2022, 15:18 last edited by@JoeCFD
Don't get me started, you don't want to know. :)
Be aware if you want to publish to the playstore you need .aab format in stead of apk and you need to update qt. But if you want permissions to work you either have to fiddle with the current workarounds or wait till it's hopefully implemented in 6.4, see my above post. -
@JoeCFD
Don't get me started, you don't want to know. :)
Be aware if you want to publish to the playstore you need .aab format in stead of apk and you need to update qt. But if you want permissions to work you either have to fiddle with the current workarounds or wait till it's hopefully implemented in 6.4, see my above post.wrote on 26 Jul 2022, 15:42 last edited by@JeanCremers Good to know. Thanks .
1/13