android get screen size via C

后端 未结 6 1465

i want to get screen size via c. i know that jni support calling java from c. but is there any person who knows another method? i mean get screen size from lowlevel modules

6条回答
  •  眼角桃花
    2020-12-11 05:21

    You can also get the window size while processing the APP_CMD_INIT_WINDOW "app command" like this in your native activity:

    static void engine_handle_cmd(struct android_app* app, int32_t cmd) {
    struct engine* engine = (struct engine*)app->userData;
    switch (cmd) {
    case APP_CMD_INIT_WINDOW:
        if (engine->app->window != NULL) {
            int width = ANativeWindow_getWidth(engine->app->window);
            int height = ANativeWindow_getHeight(engine->app->window);
        }
    

    Check out main.c in the native-activity sample NDK project if you want to know how to set up the engine struct & the engine_handle_cmd callback.

提交回复
热议问题