首页 新闻 会员 周边

用C/C++函数或API获取安卓平板的屏幕大小

0
悬赏园豆:10 [待解决问题]

各位大佬,在安卓平板上,用C/C++有什么函数或接口,可以实现获取平板的屏幕大小或像素吗?

lwei2的主页 lwei2 | 初学一级 | 园豆:198
提问于:2020-04-25 18:58
< >
分享
所有回答(2)
0

可以用 JNI 间接实现。Android肯定是可以得到平板屏幕大小的,先自定义function。那么C/C++则是通过JNI的接口调用到自己定义的方法。
希望对你有帮助。

SelfPeace | 园豆:202 (菜鸟二级) | 2020-04-26 15:53
0
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
int main()
{
        int fd;
        struct fb_var_screeninfo info;

        fd = open("/dev/fb0", O_RDWR);
        ioctl(fd, FBIOGET_VSCREENINFO, &info);
        printf("%d x %d\n", info.xres, info.yres);
        close(fd);
        return 0;
}

此程序用root权限执行

窗户 | 园豆:886 (小虾三级) | 2020-04-26 16:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册