通过C Android开屏尺寸尺寸、开屏、Android

由网友(哥的生活叫逍遥°)分享简介:我想通过C得到的屏幕尺寸。我知道,JNI支持从C调用Java。但没有任何人谁知道另一种方法?我的意思是得到低级模块,屏幕尺寸,而无需调用java的。i want to get screen size via c. i know that jni support calling java from c. but is...

我想通过C得到的屏幕尺寸。我知道,JNI支持从C调用Java。但没有任何人谁知道另一种方法?我的意思是得到低级模块,屏幕尺寸,而无需调用java的。

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 without calling java.

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity
{

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    Log.v("getWidth", Integer.toString(getWindowManager().getDefaultDisplay().getWidth()));
    Log.v("getHeight", Integer.toString(getWindowManager().getDefaultDisplay().getHeight()));
    }
}

我想的/ dev /图形是关系到我的问题

i think /dev/graphics is related to my questions

推荐答案

是的,你可以从/ dev /图形/ fb0设备的屏幕分辨率,但(至少在我的手机),读取访问仅限于根用户在图形组。无论如何,你可以做这样的事情(检查删除错误的清晰度):

Yes, you can get the screen resolution from /dev/graphics/fb0, but (at least on my phone), read access is restricted to root and users in the 'graphics' group. At any rate, you can do something like this (error checking removed for clarity):

// ... 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

我不知道,如果这些被认为是公共NDK接口,因为我如果谷歌认为机器人可以运行在Linux和使用Linux帧缓冲区接口是公共API的一部分,不知道,但它确实出现了工作。

I'm not sure if these are considered "public" NDK interfaces, since I don't know if Google considers "Android runs on Linux and uses the Linux Framebuffer interface" to be a part of the public API, but it does appear to work.

如果你想确保它是可移植的,你应该有一个后备的JNI调用到Java窗口管理器API。

If you do want to make sure it's portable, you should probably have a JNI fallback that calls into the Java WindowManager API.

阅读全文

相关推荐

最新文章