【问题标题】:How to use ScreenShotClient in my android application如何在我的 android 应用程序中使用 ScreenShotClient
【发布时间】:2012-09-15 16:08:09
【问题描述】:

我正在开发一个应用程序,它可以帮助用户捕获 android 屏幕截图 (Android 4.x)。我知道帧缓冲区在 android ICS 上已损坏。我听说我们可以使用 ScreenShotClient 来执行此操作,如下所示。

ScreenshotClient screenshotClient = new ScreenshotClient();
screenshotClient->update();

但是,我必须导入什么库才能使用它? jni代码下可以使用吗?

【问题讨论】:

标签: android android-ndk java-native-interface screenshot


【解决方案1】:

您需要的库名为 libsurfaceflinger_client.so。您可以使用命令从任何运行 Gingerbread 或更高版本 Android 的设备上拉取它

adb pull /system/lib/libsurfaceflinger_client.so

在 ICS 或 JB 上,类 ScreenshotClientlibgui.so 的一部分。 screencap 的 makefile 是使用 ScreenshotClient 的示例,表明链接器可能需要其他库:

libcutils libutils libbinder libskia libui libgui

另外,screencap.cpp 的代码如下:

ScreenshotClient screenshot;
if (screenshot.update() == NO_ERROR) {
    base = screenshot.getPixels();
    w = screenshot.getWidth();
    h = screenshot.getHeight();
    f = screenshot.getFormat();
    size = screenshot.getSize();
} else {
    const char* fbpath = "/dev/graphics/fb0";
    int fb = open(fbpath, O_RDONLY);
    if (fb >= 0) {
        struct fb_var_screeninfo vinfo;
        if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) == 0) {
...

这意味着至少您必须检查 update() 是否成功。不幸的是,除非设备已获得 root 权限,否则无法授予应用程序从/dev/graphics/fb0 读取的权限并使用/system/bin/screencap/system/bin/screenshot 的后备。

【讨论】:

  • 是的。我可以将它从那个文件夹拉到我的项目中。但我不知道如何使用它来捕获android屏幕。你能给我一些提示吗?
  • 等一下。您在其他地方写道,您的项目中有代码,但无法构建它,因为您不知道在哪里可以找到 .so 文件
  • 嗯。 adb 命令不适用于运行 Android 4.1.1 的设备。:远程对象 '/system/lib/libsurfaceflinger_client.so' 不存在
  • 好吧,在 4.0 及更高版本中,该库被称为 libgui.soscreencap 的生成文件是 使用 ScreenshotClient 的示例,表明链接器可能需要其他库:libcutils libutils libbinder libskia libui libgui
猜你喜欢
  • 2012-01-26
  • 2015-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-31
  • 2011-01-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多