2

I am developing an application which helps user to capture android screen shot (Android 4.x) . I know that framebuffer is broken on android ICS. I hear that we can use ScreenShotClient to do this as below.

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

But, what library I have to import to use it? Is it available to use under jni code?

Nguyen Minh Binh
  • 23,891
  • 30
  • 115
  • 165
  • Isn't this duplicate of http://stackoverflow.com/questions/2661536/screenshot-android? – Alex Cohn Sep 25 '12 at 13:43
  • No. the answers at that question didn't help. – Nguyen Minh Binh Sep 26 '12 at 03:06
  • OK, have you seen the answer in [**how-to-capture-the-android-device-screen-content**](http://stackoverflow.com/questions/3067586/how-to-capture-the-android-device-screen-content#7979151)? – Alex Cohn Sep 27 '12 at 19:46
  • Yes, I did. I wrote a similar app which using ScreenShotClient to take screenshot, but I couldn't build it. The needed library was not found. – Nguyen Minh Binh Sep 28 '12 at 02:29
  • Have you found the **surfaceflinger_client/SurfaceComposerClient.h** file? – Alex Cohn Sep 28 '12 at 19:14
  • I downloaded that file (and many other needed files) from https://github.com/android then put them into /jni folder but I can't build it. My JNI folder was shared here: https://dl.dropbox.com/u/15261504/jni.zip – Nguyen Minh Binh Oct 01 '12 at 03:30

1 Answers1

7

The library you need is called libsurfaceflinger_client.so. You can pull it from any device running Gingerbread or higher version of Android, with command

adb pull /system/lib/libsurfaceflinger_client.so

On ICS or JB, class ScreenshotClient is part of libgui.so. The makefile for screencap which is the example of using ScreenshotClient, suggests that linker may need other libraries:

libcutils libutils libbinder libskia libui libgui

Also, the code of screencap.cpp goes as follows:

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) {
...

This means that at least you must check that update() succeed. Unfortunately, unless teh device is rooted, the apps cannot be granted permission to read from /dev/graphics/fb0 and use the fallback of /system/bin/screencap or /system/bin/screenshot.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Yeah. I can pull it from that folder to my Project. But I don't know how to use it to capture android screen. Could you give me some hints? – Nguyen Minh Binh Oct 01 '12 at 03:35
  • Wait a sec. You wrote elsewhere that you have the code in your project, but cannot build it because you don't know where to find the **.so** file – Alex Cohn Oct 01 '12 at 04:37
  • Hm. The adb command does not work for my device running Android 4.1.1.: **remote object '/system/lib/libsurfaceflinger_client.so' does not exist** – Claas Wilke Oct 02 '12 at 09:24
  • 1
    Well, on 4.0 and higher the library is called **libgui.so**. The makefile for `screencap` which is ***the*** example of using **ScreenshotClient**, suggests that linker may need other libraries: `libcutils libutils libbinder libskia libui libgui`. – Alex Cohn Oct 02 '12 at 10:49