Facing Problem with New Window API Android SDK >= 30 using QJniObject
-
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;"
-
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.
-
@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. -
@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.
-
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.
-
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