Hello,
There are some changes in BLE scanning for Android 12.
New permissions are required and the location is no more needed.
The problem is that when I start a Scan it keeps asking for the location to be enabled.
I am missing something ?
Here is my permission setup :
<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_CONNECT"/>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation"/>
<!--<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" android:maxSdkVersion="30"/>-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature android:name="android.hardware.bluetooth" android:required="true"/>
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-feature android:name="android.hardware.location"/>
<uses-feature android:name="android.hardware.screen.portrait"/>
note: the ACCESS_COARSE_LOCATION
should be with android:maxSdkVersion="30"
but in that case the scan is not working.
I also added in my C++ (before scanning) :
#ifndef Q_OS_MAC
bool Ble_Central::requestPermission(void) {
QString scanPerm = "android.permission.BLUETOOTH_SCAN";
QString connPerm = "android.permission.BLUETOOTH_CONNECT";
if(QtAndroid::androidSdkVersion() >= 31) {
auto results = QtAndroid::requestPermissionsSync(QStringList{scanPerm, connPerm});
if (!results.contains(scanPerm) || results[scanPerm] == QtAndroid::PermissionResult::Denied) {
qWarning() << "Couldn't get permission: " << scanPerm;
return false;
}
if (!results.contains(connPerm) || results[connPerm] == QtAndroid::PermissionResult::Denied) {
qWarning() << "Couldn't get permission: " << connPerm;
return false;
}
}
return true;
}
#else
bool Ble_Central::requestPermission(void) {
return true;
}
#endif
If I’m correct, QT is always asking for the location, not checking the sdk.
The scan is also not asking BLUETOOTH_SCAN and BLUETOOTH_CONNECT so I need to do it manually.
Do you have a fix for this behavior ?
Cordially,
Allan