Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QAndroidJniObject::getStaticObjectField ... problems



  • Hi kind reader. I trying to get my head around QT +Android.
    Writing app to work with IOT (ESP-32) but Qt didn't have a wrapper for manage WiFi, so JNI is my only option here.

    My goal is to check the current connection, status BSSID etc. Next disconnect from it connect to hidden SSID of IOT ( when i setup mode ) ask the user for the password for this AP pass BSSID and password as a config to IOT, disconnect from IOT when it restarts Delete it from Android BSSID list and reconnects to origin BSSID.
    But as always I hit the wall, QAndroidJniObject didn't want to play with me.

    QAndroidJniObject activity = QAndroidJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative", "activity", "()Landroid/app/Activity;");
    if ( activity.isValid() )
    {
        QAndroidJniObject serviceName = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Context","WIFI_SERVICE");
        if ( serviceName.isValid() ){
    
            QAndroidJniObject wifiMgr = activity.callObjectMethod("getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;",serviceName.object<jobject>());
            if ( wifiMgr.isValid() ){
    
                jint wifiStateEnabled = QAndroidJniObject::getStaticField<jint>("android/net/wifi/WifiManager","WIFI_STATE_ENABLED");
    
               QAndroidJniObject j_String = QAndroidJniObject::getStaticObjectField("android/net/wifi/WifiManager","EXTRA_WIFI_INFO","()Ljava/lang/String;");
    
                qDebug() << " extra info=" <<  j_String.toString() << "Wifi_State =" << wifiStateEnabled ; // wifi  enabled =3 
            }
        }
       }
    

    and I geting this ..

    from app Output ...
    I Timeline: Timeline: Activity_idle id: android.os.BinderProxy@b2ee161 time:601456834
    I ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
    I ViewRootImpl: ViewRoot's Touch Event : ACTION_UP
    W System.err: java.lang.NoSuchFieldError: no type "()Ljava/lang/String;" found and so no field "EXTRA_WIFI_INFO" could be found in class "Landroid/net/wifi/WifiManager;" or its superclasses
    W System.err: at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
    W System.err: at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:387)
    W System.err: at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
    W System.err: at java.lang.Thread.run(Thread.java:818)
    W System.err: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
    D libQT_Android_Java_Test.so: extra info= "" Wifi_State = 3

    I can get staticField when it is primitive type but when trying to access string or object no type found ... no field.
    any idea how to access this


Log in to reply