Sunday, 8 September 2013

How to get the screen size of Android device via C?

How to get the screen size of Android device via C?

I want to get screen size via C. I know we can use JNI to call Java from
c. But is there any way to get via C directly? I mean get screen size from
lowlevel modules without calling Java but just C. I used these codes
below, but doesn't work, it returns width:10925409 and height:0:
// ... Other standard includes ...
#include <sys/ioctl.h>
#include <linux/fb.h>
//...
struct fb_var_screeninfo fb_var;
int fd = open("/dev/graphics/fb0", O_RDONLY);
ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);
close(fd);
// screen size will be in fb_var.xres and fb_var.yres

No comments:

Post a Comment