When running an app on a mobile phone using Bluetooth with Qt 6.8 for Android, there is an error indicating lack of permission
-
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_;
-
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_;
@ljxiango Does your app request permissions?
See https://doc.qt.io/qt-6/permissions.html -
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) -
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)@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. -
@ljxiango Does your app request permissions?
See https://doc.qt.io/qt-6/permissions.html@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? -
@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.