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. When running an app on a mobile phone using Bluetooth with Qt 6.8 for Android, there is an error indicating lack of permission

When running an app on a mobile phone using Bluetooth with Qt 6.8 for Android, there is an error indicating lack of permission

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
6 Posts 3 Posters 171 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.
  • L Offline
    L Offline
    ljxiango
    wrote on last edited by
    #1

    Hi everyone, I have a question about using Bluetooth in Qt for Android. The same code worked on Qt 5.14.2 with an Android 10 device to scan Bluetooth devices, but now with Qt 6.8, it throws a "no permission" error. I’ve spent a day trying to fix it but no luck. Any help?
    Qt 5.14.2 build settings: SDK Platform-Tools 29.0.6, Build-Tools 28.0.3, Android 8.
    Qt 6.8 build settings: SDK Platform 35, Build-Tools 35.0.0, build platform SDK android-35.
    use: QBluetoothLocalDevice localDev_;
    error.png

    jsulmJ 1 Reply Last reply
    0
    • L ljxiango

      Hi everyone, I have a question about using Bluetooth in Qt for Android. The same code worked on Qt 5.14.2 with an Android 10 device to scan Bluetooth devices, but now with Qt 6.8, it throws a "no permission" error. I’ve spent a day trying to fix it but no luck. Any help?
      Qt 5.14.2 build settings: SDK Platform-Tools 29.0.6, Build-Tools 28.0.3, Android 8.
      Qt 6.8 build settings: SDK Platform 35, Build-Tools 35.0.0, build platform SDK android-35.
      use: QBluetoothLocalDevice localDev_;
      error.png

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ljxiango Does your app request permissions?
      See https://doc.qt.io/qt-6/permissions.html

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

      L 1 Reply Last reply
      1
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote last edited by JoeCFD
        #3

        Android 12 (API 31) and Later
        Required permissions:
        BLUETOOTH (normal permission - granted at install time)
        BLUETOOTH_CONNECT (runtime permission - must be requested)
        BLUETOOTH_SCAN (runtime permission - if scanning for devices)

        Android 6.0 (API 23) to Android 11 (API 30)
        Required permissions:
        BLUETOOTH (normal permission)
        BLUETOOTH_ADMIN (normal permission - if you need to scan/pair)
        ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION (runtime permission - required for scanning)

        L 1 Reply Last reply
        1
        • JoeCFDJ JoeCFD

          Android 12 (API 31) and Later
          Required permissions:
          BLUETOOTH (normal permission - granted at install time)
          BLUETOOTH_CONNECT (runtime permission - must be requested)
          BLUETOOTH_SCAN (runtime permission - if scanning for devices)

          Android 6.0 (API 23) to Android 11 (API 30)
          Required permissions:
          BLUETOOTH (normal permission)
          BLUETOOTH_ADMIN (normal permission - if you need to scan/pair)
          ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION (runtime permission - required for scanning)

          L Offline
          L Offline
          ljxiango
          wrote last edited by
          #4

          @JoeCFD
          Thank you for your answer!
          In the AndroidManifest.xml file located in the android-build folder, there are permission-related contents:
          <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
          <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
          <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
          <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
          <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" android:minSdkVersion="31" />
          <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:minSdkVersion="31" />
          <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:minSdkVersion="31" android:usesPermissionFlags="neverForLocation" />
          <uses-permission android:name="android.permission.INTERNET" />
          <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
          However, when the program runs on the phone, the dialog box for obtaining location permissions does not appear, which causes the Bluetooth initialization to fail.
          Previously, with Qt 5.14.2, the dialog box for obtaining location permissions would pop up the first time the program was launched. After switching to Qt 6.8, I don't know why it no longer appears.

          JoeCFDJ 1 Reply Last reply
          0
          • jsulmJ jsulm

            @ljxiango Does your app request permissions?
            See https://doc.qt.io/qt-6/permissions.html

            L Offline
            L Offline
            ljxiango
            wrote last edited by
            #5

            @jsulm
            Thank you for your answer!
            In the AndroidManifest.xml file located in the android-build folder, there are permission-related contents. However, when the program runs on the phone, the dialog box for obtaining location permissions does not appear, which causes the Bluetooth initialization to fail.
            For now, I can only temporarily obtain location permissions in the code through QLocationPermission.
            Previously, with Qt 5.14.2, the dialog box for obtaining location permissions would pop up the first time the program was launched. After switching to Qt 6.8, I don’t know why it no longer appears. Do I need to add QLocationPermission to make the dialog box for obtaining location permissions appear?

            1 Reply Last reply
            0
            • L ljxiango

              @JoeCFD
              Thank you for your answer!
              In the AndroidManifest.xml file located in the android-build folder, there are permission-related contents:
              <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
              <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
              <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
              <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
              <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" android:minSdkVersion="31" />
              <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" android:minSdkVersion="31" />
              <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:minSdkVersion="31" android:usesPermissionFlags="neverForLocation" />
              <uses-permission android:name="android.permission.INTERNET" />
              <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
              However, when the program runs on the phone, the dialog box for obtaining location permissions does not appear, which causes the Bluetooth initialization to fail.
              Previously, with Qt 5.14.2, the dialog box for obtaining location permissions would pop up the first time the program was launched. After switching to Qt 6.8, I don't know why it no longer appears.

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote last edited by
              #6

              @ljxiango
              maybe use qt code to check permissions.
              https://doc.qt.io/qt-6/qtandroidprivate.html

              Qt6 has a lot of changes. Do not expect everything is the same.

              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