android get screen size via C

后端 未结 6 1440

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:26

    For anyone like me who is looking for a pure C++ way of doing this, reading /dev/graphics/fb0 does not work reliably. On many devices, it returns an incorrect result (on mine it returns 640 X 400).

    This is a problem for situations in which you cannot use ANativeWindow or ANativeWindow_Buffer, for example in a native binary executable.

    What worked for me :

    Assuming you have a rooted phone, you can process the output of the below command to read the resolution reliably.

    su -c dumpsys display | grep mBaseDisplayInfo
    

提交回复
热议问题