Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Example code for applying for Android permissions in QT 6.5.3.

Example code for applying for Android permissions in QT 6.5.3.

Scheduled Pinned Locked Moved Unsolved Qt 6
qt6android
6 Posts 3 Posters 499 Views
  • 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.
  • G Offline
    G Offline
    Gracy
    wrote on 7 Nov 2024, 04:30 last edited by
    #1

    Hey everyone! I'm currently working on a project using QT 6.5.3 and I need to apply for Android permissions. But I'm kind of stuck and not sure how to do it exactly. Does anyone have some example code for applying for Android permissions in QT 6.5.3 that they could share with me? Thanks a lot in advance!

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 7 Nov 2024, 06:43 last edited by
      #2

      Take a look at https://doc.qt.io/qt-6/permissions.html

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

      G 1 Reply Last reply 7 Nov 2024, 08:04
      0
      • J jsulm
        7 Nov 2024, 06:43

        Take a look at https://doc.qt.io/qt-6/permissions.html

        G Offline
        G Offline
        Gracy
        wrote on 7 Nov 2024, 08:04 last edited by
        #3

        @jsulm Thank you very much for your answer. QT6 already has only these few permissions built-in.(QBluetoothPermission,QCalendarPermission,QCameraPermission,QContactsPermission,QLocationPermission,QMicrophonePermission)
        If I want to apply for Wi-Fi permission, specifically "android.permission.CHANGE_WIFI_STATE", I don't know how to achieve it. And for other permissions that are not built-in, how can I apply for them?

        J 1 Reply Last reply 7 Nov 2024, 08:49
        0
        • G Gracy
          7 Nov 2024, 08:04

          @jsulm Thank you very much for your answer. QT6 already has only these few permissions built-in.(QBluetoothPermission,QCalendarPermission,QCameraPermission,QContactsPermission,QLocationPermission,QMicrophonePermission)
          If I want to apply for Wi-Fi permission, specifically "android.permission.CHANGE_WIFI_STATE", I don't know how to achieve it. And for other permissions that are not built-in, how can I apply for them?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 7 Nov 2024, 08:49 last edited by
          #4

          @Gracy Try to add the permissions to AndroidManifest.xml. But I don't know how you can check whether the permission was granted.

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

          G 1 Reply Last reply 7 Nov 2024, 09:01
          0
          • J jsulm
            7 Nov 2024, 08:49

            @Gracy Try to add the permissions to AndroidManifest.xml. But I don't know how you can check whether the permission was granted.

            G Offline
            G Offline
            Gracy
            wrote on 7 Nov 2024, 09:01 last edited by
            #5

            I've tried it.
            QT6.5.3 automatically generates XML files, and manual modifications don't take effect.
            In addition, I have tried adding the permission in the.pro file ,by adding "ANDROID_PERMISSIONS += android.permission.CHANGE_WIFI_STATE" or ANDROID_MANIFEST method, but neither of them has been successful.

            F 1 Reply Last reply 13 days ago
            0
            • G Gracy
              7 Nov 2024, 09:01

              I've tried it.
              QT6.5.3 automatically generates XML files, and manual modifications don't take effect.
              In addition, I have tried adding the permission in the.pro file ,by adding "ANDROID_PERMISSIONS += android.permission.CHANGE_WIFI_STATE" or ANDROID_MANIFEST method, but neither of them has been successful.

              F Offline
              F Offline
              felsi
              wrote 13 days ago last edited by felsi
              #6

              @Gracy
              The question is pretty old, but i know the answer...
              First, make sure, the permissions are added.
              Maybe you are missing the following:
              https://doc.qt.io/qtcreator/creator-deploying-android.html#editing-manifest-files

              To check and request permissions you can do:

              QFuture permission_request = QtAndroidPrivate::requestPermission("android.permission.WRITE_EXTERNAL_STORAGE");
              
              switch(permission_request.result())
              {
              case QtAndroidPrivate::Undetermined:
                  qWarning() << "Permission for writing to the storage undetermined!";
                  break;
              case QtAndroidPrivate::Authorized:
                  qDebug() << "Permission for writing to the storage authorized";
                  break;
              case QtAndroidPrivate::Denied:
                  qWarning() << "Permission for writing to the storage denied!";
                  break;
              }
              
              1 Reply Last reply
              0

              • Login

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