dmGraphics::GetNativeAndroidActivity can not get Window object in cpp source code

hello , I want to get window object by dmGraphics::GetNativeAndroidActivity on android. but now I get nullpoint jobject by JNI. I don` known why, for this code , it was run on android project can get window object. so can u help me to resolved this problem , the source code like this.

--SOURCE
jclass activity_class = env->GetObjectClass(dmGraphics::GetNativeAndroidActivity());

jmethodID get_window_method = env->GetMethodID(activity_class, "getWindow",
"()Landroid/view/Window;");

jobject window_object = env->CallObjectMethod(dmGraphics::GetNativeAndroidActivity(),get_window_method);

Log::println("setFullscreen: get window object , %p",window_object);
--END

now i print window_object point address is 0x0. I checked that dmGraphics::GetNativeAndroidActivity() point address is not null , env is not null.

Please help , Thanks…

Check the safearea extension where we do something similar:

1 Like

hello, Thanks for reply . I resolved this problem by using class_loader to load class, but i found that this method is only run android version >=api 28 ? if i want to run android 27 or lower , have any idea ?

What do you mean? Are you getting an error? Which line of code?

If you’re referring to this code, it’s because the feature of the WindowInsetsCompat.getDisplayCutout()) requires API level 28.

Getting the Window doesn’t require API level 28, so no need to check that in your case.

3 Likes