Details
-
Bug
-
Resolution: Incomplete
-
P1: Critical
-
5.15.0
-
Qt: 5.15.0
Build Machine: Mac Catalina 10.15.6
Android NDK: 20.0.5594570
Android device: Samsung Galaxy Tab A, Android 10
Description
I am writing an JNI library that using Qt Bluetooth (i.e.
`QBluetoothDeviceDiscoveryAgent` class). When loading this library and run on Android device, I see this warning:
2020-10-26 11:51:49.016 28243-28917/com.example.appwithqtlib W/MyLibWithQt.framework: qt.bluetooth.android: Device does not support Bluetooth
and the discovery doesn't run.
I looked into the implementation of this class and try to reproduce this issue with this code:
QAndroidJniEnvironment env; QAndroidJniObject adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter", "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;"); if (!adapter.isValid()) { if (env->ExceptionCheck()) { env->ExceptionDescribe(); env->ExceptionClear(); } qWarning() << "MyLibWithQt: Device does not support Bluetooth"; }
It prints "MyLibWithQt: Device does not support Bluetooth".
If I change the code a little bit:
QAndroidJniEnvironment env; jclass btAdapterClass = env->FindClass("android/bluetooth/BluetoothAdapter"); if (btAdapterClass == NULL) { qWarning() << "Native registration unable to find class android/bluetooth/BluetoothAdapter"; } QAndroidJniObject adapter = QAndroidJniObject::callStaticObjectMethod(btAdapterClass, "getDefaultAdapter", "()Landroid/bluetooth/BluetoothAdapter;"); if (!adapter.isValid()) { if (env->ExceptionCheck()) { env->ExceptionDescribe(); env->ExceptionClear(); } qWarning() << "MyLibWithQt: Device does not support Bluetooth"; }
then it doesn't print "MyLibWithQt: Device does not support Bluetooth" anymore.
Do you guys have any idea?
P/S: I see a same guy got the same issue here