3

I'm trying to record android screenshots when I'm drawing something on the screen and after generate a video. I'm thought to do this with a "for" looping but I had problems when I called the getDrawingCache() method. In principle it works right, but if I change something on screen when the "drawing cache" is called, the android app is closed without error reported. Below is my source code.

public void run() {
        Bitmap screenshot;
        File file;
        FileOutputStream fileOutputStream;

        this.view.setDrawingCacheEnabled(true);

        for (long i = 1; record; i++) {

            screenshot = (Bitmap) Bitmap.createBitmap(view.getDrawingCache());

            file = new File(directory, "frm" + i + ".jpg");

            try {
                fileOutputStream = new FileOutputStream(file);

                screenshot.compress(CompressFormat.JPEG, 10, fileOutputStream);

                fileOutputStream.close();
                ScreenshotRecorder.sleep(50);

            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        this.view.setDrawingCacheEnabled(false);

    }

I've looked for another way to get android screen recorder, but I've not found open source apps. If someone know some way how to get android screen capture, I'm grateful. Thanks for all.

(I'm using a Xoom Tablet and android 3.0 version)

Josmário
  • 31
  • 2

2 Answers2

0

I believe you need to call view.buildDrawingCache(...) before you call get drawing cache, or there will be nothing to get. You can read about this here.

mtmurdock
  • 12,756
  • 21
  • 65
  • 108
0

Try:

view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache(true);

From my answer Here to avoid null image

Community
  • 1
  • 1
Imran Rana
  • 11,899
  • 7
  • 45
  • 51
  • Unfortunately, this doesn't works. I try it into the for block, but the app is closed without no erro reported. Do you know some app to take screen recorder on android Xoom not rooting? – Josmário May 24 '12 at 17:22