Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-87854

Problem to use QAndroidJniObject (as a part of QBluetoothDeviceDiscoveryAgent)

    XMLWordPrintable

    Details

    • Platform/s:
      Android

      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

        Attachments

        1. qtbug87854.zip
          3 kB
        2. qtbug87854SL.zip
          63 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            whoistheguilty Tapio Oksa
            Reporter:
            thamha Tham Thi Ha
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes