Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Facing Problem with New Window API Android SDK >= 30 using QJniObject

Facing Problem with New Window API Android SDK >= 30 using QJniObject

Scheduled Pinned Locked Moved Solved Mobile and Embedded
android 11windowinsetsjniapi 30
9 Posts 3 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kafabih
    wrote on 16 Dec 2022, 04:32 last edited by Kafabih
    #1

    Hello everyone, is anybody can show me how to use new window API for Android R alias SDK => 30 by using QJniObject? I am have problem here for calling many method on new window API. Do not tell me to using java instead, because I want to made the code purely using c++ without java.

    Here sample I call WindowInsetsController object but the logcat said no such method.

    QJniObject activity = QNativeInterface::QAndroidApplication::context();
    QJniObject window = activity.callObjectMethod("getWindow","()Landroid/view/Window;");
    QJniObject decorview = window.callObjectMethod("getDecorView","()Landroid/view/View;");
    QJniObject insets = decorview.callObjectMethod("getWindowInsetsController","()Landroid/view/Window;");
    

    Error said if I using decorview to call WindowInsetsController

    java.lang.NoSuchMethodError: no non-static method "Lcom/android/internal/policy/DecorView;.getWindowInsetsController()Landroid/view/Window;"
    

    Error said if I just using window to call WindowInsetsController

    java.lang.NoSuchMethodError: no non-static method "Lcom/android/internal/policy/PhoneWindow;.getWindowInsetsController()Landroid/view/Window;"
    
    J 1 Reply Last reply 16 Dec 2022, 06:17
    0
    • K Kafabih
      16 Dec 2022, 04:32

      Hello everyone, is anybody can show me how to use new window API for Android R alias SDK => 30 by using QJniObject? I am have problem here for calling many method on new window API. Do not tell me to using java instead, because I want to made the code purely using c++ without java.

      Here sample I call WindowInsetsController object but the logcat said no such method.

      QJniObject activity = QNativeInterface::QAndroidApplication::context();
      QJniObject window = activity.callObjectMethod("getWindow","()Landroid/view/Window;");
      QJniObject decorview = window.callObjectMethod("getDecorView","()Landroid/view/View;");
      QJniObject insets = decorview.callObjectMethod("getWindowInsetsController","()Landroid/view/Window;");
      

      Error said if I using decorview to call WindowInsetsController

      java.lang.NoSuchMethodError: no non-static method "Lcom/android/internal/policy/DecorView;.getWindowInsetsController()Landroid/view/Window;"
      

      Error said if I just using window to call WindowInsetsController

      java.lang.NoSuchMethodError: no non-static method "Lcom/android/internal/policy/PhoneWindow;.getWindowInsetsController()Landroid/view/Window;"
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 16 Dec 2022, 06:17 last edited by
      #2

      @Kafabih I'm not an Android expert but the error says that there is no such non-static method. Maybe you need to call it using callStaticMethod?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kafabih
        wrote on 16 Dec 2022, 06:40 last edited by
        #3

        I have tried by calling as static object as below

        QJniObject insets = window.callStaticObjectMethod("()Landroid/view/WindowInsetsController;","getWindowInsetsController","Ljava/lang/Object;");
        

        but it cause error as below

        System.err: java.lang.ClassNotFoundException: Didn't find class "()Landroid.view.WindowInsetsController;"
        

        According this reference getWindowInsets can call by calling window class, but it facing no class found. This is weird.

        J 1 Reply Last reply 16 Dec 2022, 06:43
        0
        • K Kafabih
          16 Dec 2022, 06:40

          I have tried by calling as static object as below

          QJniObject insets = window.callStaticObjectMethod("()Landroid/view/WindowInsetsController;","getWindowInsetsController","Ljava/lang/Object;");
          

          but it cause error as below

          System.err: java.lang.ClassNotFoundException: Didn't find class "()Landroid.view.WindowInsetsController;"
          

          According this reference getWindowInsets can call by calling window class, but it facing no class found. This is weird.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 16 Dec 2022, 06:43 last edited by
          #4

          @Kafabih According to the link you posted you can call it using Landroid/view/View?

          Landroid/view/View;->getWindowInsetsController()Landroid/view/WindowInsetsController;
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          K 1 Reply Last reply 16 Dec 2022, 10:00
          0
          • J jsulm
            16 Dec 2022, 06:43

            @Kafabih According to the link you posted you can call it using Landroid/view/View?

            Landroid/view/View;->getWindowInsetsController()Landroid/view/WindowInsetsController;
            
            K Offline
            K Offline
            Kafabih
            wrote on 16 Dec 2022, 10:00 last edited by
            #5

            @jsulm I already using getDecorView from android/view/View class as mentioned before still no class found.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JoeCFD
              wrote on 16 Dec 2022, 15:02 last edited by JoeCFD
              #6

              @Kafabih said in Facing Problem with New Window API Android SDK => 30 using QJniObject:

              android/view/WindowInsetsControlle

              Are you using Qt5 or 6? Does your return type android/view/Window or android/view/View exist?
              https://doc.qt.io/qt-5/qandroidjniobject.html
              Qt Jni works this way: send context into Java code and do things as needed in Java code and then return what is defined in the link above? You can not get what is defined in Java. Qt Jni is an interface between android native Java lib and Qt.

              1 Reply Last reply
              0
              • K Offline
                K Offline
                Kafabih
                wrote on 17 Dec 2022, 06:57 last edited by
                #7

                @JoeCFD I using QT 6 for developing app. Did QT6 adding androidx support? Because when I call androidx using

                QJniObject activity = QNativeInterface::QAndroidApplication::context(); 
                QJniObject window = activity.callObjectMethod("getWindow","()Landroidx/view/WindowCompat;");
                

                Logcat said error no method found androidx.

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  Kafabih
                  wrote on 17 Dec 2022, 07:13 last edited by Kafabih
                  #8

                  Alright sorry for my bad for WindowInsets calling. Since 2020 when android 11 released. DecorView has separated api to controlling SystemUI. It is called WindowInsetsController. And for this you need to call android/view/WindowInsetsController as below.

                  QJniObject insets = decorview.callObjectMethod("getWindowInsetsController","()Landroid/view/WindowInsetsController;");
                  

                  But I cannot determining which navigation bar visibility by using WindowInsets as below.

                  QJniObject insets = decorview.callObjectMethod("getRootWindowInsets","()Landroid/view/WindowInsets;");
                  bool isNavbarVisible = insets.callMethod<jboolean>("isVisible","(I)Z",2);
                  

                  The logcat always shown no such method.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    Kafabih
                    wrote on 18 Dec 2022, 02:07 last edited by Kafabih
                    #9

                    After spending more hours to exploring the new Window API on SDK >= 30 I have conclusion with this new Window API. The WindowInsets did not separate from DecorView, but this WindowInsets is inherited from DecorView, so you must calling DecorView first. Thanks for yours helps especially @JoeCFD for remembering me to write the correct return type. Here I gave pieces codes to facing the new Android API as Holiday gift 2022 pieces codes to facing new Android API SDK >= 30

                    1 Reply Last reply
                    0

                    8/9

                    17 Dec 2022, 07:13

                    • Login

                    • Login or register to search.
                    8 out of 9
                    • First post
                      8/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved