我正在尝试使用 NDK 在 NativeActivity 应用程序中获取Android DisplayMetrics类。我试图调用的函数是这些行中的函数:
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = this.getWindowManager();
Display display = wm.getDefaultDisplay();
display.getMetrics(metrics);
到目前为止,我已经完成了对象设置和方法调用,如下所示
JNIEnv *jni;
state->activity->vm->AttachCurrentThread(&jni, NULL);
jclass activityClass = jni->FindClass("android/app/NativeActivity");
jclass windowManagerClass = jni->FindClass("android/view/WindowManager");
jclass displayClass = jni->FindClass("android/view/Display");
jclass displayMetricsClass = jni->FindClass("android/util/DisplayMetrics");
jmethodID getWindowManager = jni->GetMethodID(activityClass, "getWindowManager", "()Landroid/view/WindowManager;");
jmethodID getDefaultDisplay = jni->GetMethodID(windowManagerClass, "getDefaultDisplay", "()Landroid/view/Display;");
jmethodID getMetrics = jni->GetMethodID(displayClass, "getMetrics", "(android/util/DisplayMetrics)L;");
jmethodID newDisplayMetrics = jni->GetMethodID(displayMetricsClass, "DisplayMetrics", "()Landroid/util/DisplayMetrics;");
jobject metrics = jni->CallObjectMethod(displayMetricsClass, newDisplayMetrics);
jobject windowManager = jni->CallObjectMethod(state->activity->clazz, getWindowManager);
jobject display = jni->CallObjectMethod(windowManager, getDefaultDisplay);
但是,现在我不知道如何通过引用将指标 jobject 传递给 display.getmetrics() 函数,以便让操作系统对其进行调整并正确填写,以便我可以读取其中的字段