Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to use QtAndroidPrivate::checkPermission ?
Forum Updated to NodeBB v4.3 + New Features

How to use QtAndroidPrivate::checkPermission ?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
13 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JeanCremers
    wrote on 26 Jul 2022, 09:26 last edited by
    #1

    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 QFuture

    I'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.

    J 1 Reply Last reply 26 Jul 2022, 10:00
    0
    • J JeanCremers
      26 Jul 2022, 09:26

      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 QFuture

      I'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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 26 Jul 2022, 10:00 last edited by
      #2

      @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) {
          ...
      });
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • J Offline
        J Offline
        JeanCremers
        wrote on 26 Jul 2022, 10:15 last edited by JeanCremers
        #3

        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

        J 1 Reply Last reply 26 Jul 2022, 10:20
        0
        • J JeanCremers
          26 Jul 2022, 10:15

          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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 26 Jul 2022, 10:20 last edited by
          #4

          @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
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JeanCremers
            wrote on 26 Jul 2022, 10:38 last edited by
            #5

            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;
            }
            
            J 1 Reply Last reply 26 Jul 2022, 10:45
            0
            • J JeanCremers
              26 Jul 2022, 10:38

              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;
              }
              
              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 26 Jul 2022, 10:45 last edited by
              #6

              @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;
              }
              

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • J Offline
                J Offline
                JeanCremers
                wrote on 26 Jul 2022, 11:19 last edited by
                #7

                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. :(

                J 1 Reply Last reply 26 Jul 2022, 11:30
                0
                • J JeanCremers
                  26 Jul 2022, 11:19

                  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. :(

                  J Offline
                  J Offline
                  JeanCremers
                  wrote on 26 Jul 2022, 11:30 last edited by JeanCremers
                  #8

                  I 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.

                  1 Reply Last reply
                  0
                  • JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on 26 Jul 2022, 13:19 last edited by
                    #9

                    Did you add this in your pro file?
                    QT += androidextras

                    Just 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.

                    J 1 Reply Last reply 26 Jul 2022, 13:34
                    0
                    • JoeCFDJ JoeCFD
                      26 Jul 2022, 13:19

                      Did you add this in your pro file?
                      QT += androidextras

                      Just 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.

                      J Offline
                      J Offline
                      JeanCremers
                      wrote on 26 Jul 2022, 13:34 last edited by
                      #10

                      @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.

                      JoeCFDJ 1 Reply Last reply 26 Jul 2022, 15:05
                      0
                      • J JeanCremers
                        26 Jul 2022, 13:34

                        @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.

                        JoeCFDJ Offline
                        JoeCFDJ Offline
                        JoeCFD
                        wrote on 26 Jul 2022, 15:05 last edited by JoeCFD
                        #11

                        @JeanCremers True it is for 5. Things in Qt6 are different. Great: another round of learning.

                        J 1 Reply Last reply 26 Jul 2022, 15:18
                        0
                        • JoeCFDJ JoeCFD
                          26 Jul 2022, 15:05

                          @JeanCremers True it is for 5. Things in Qt6 are different. Great: another round of learning.

                          J Offline
                          J Offline
                          JeanCremers
                          wrote on 26 Jul 2022, 15:18 last edited by
                          #12

                          @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.

                          JoeCFDJ 1 Reply Last reply 26 Jul 2022, 15:42
                          0
                          • J JeanCremers
                            26 Jul 2022, 15:18

                            @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.

                            JoeCFDJ Offline
                            JoeCFDJ Offline
                            JoeCFD
                            wrote on 26 Jul 2022, 15:42 last edited by
                            #13

                            @JeanCremers Good to know. Thanks .

                            1 Reply Last reply
                            0

                            1/13

                            26 Jul 2022, 09:26

                            • Login

                            • Login or register to search.
                            1 out of 13
                            • First post
                              1/13
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved