1

I am trying to capture my activity's screen on android. I am using the code below:

View root = this.activity.getWindow().getDecorView().getRootView();

Bitmap b = Bitmap.createBitmap(root.getWidth(), root.getHeight(), Config.RGB_565);
Canvas c = new Canvas(b);
root.draw(c);

if (b != null && !b.isRecycled()) {
    this.screen = Bitmap.createBitmap(b);
}

If on-screen keyboard pops up, then I've got only visible part of my activity's window in this.screen and the rest is blank.

Is there any way to get my app's screenshot, including the parts, that are under on-screen keyboard?

vault
  • 3,930
  • 1
  • 35
  • 46
cheshie
  • 421
  • 1
  • 6
  • 18
  • i start showing you [this](http://stackoverflow.com/a/4290532/1521064) if you have problems with the screenshot being squeezed – vault Feb 08 '13 at 18:09
  • screenshot is not squeezed. on screenshot present only that objects, which are above on-screen keyboard. everything else (i.e., objects that are under keyboard) is blank. I need to have them on the screenshot too. – cheshie Feb 08 '13 at 18:45

1 Answers1

2

I'm sorry to dissapoint you, but this cannot be done without external aid. The keyboard is simply not a part of your application layout.

Your "outermost" view is the DecorView, which you are already snapping. That's as far as this technique goes.

Edit: I can't try it now, but give this a go:

View topmost = ((ViewGroup)
     ctx.getWindow().getDecorView().findViewById(android.R.id.content)
).getChildAt(0);

topmost.setDrawingCacheEnabled(true);

Bitmap screenshot = topmost.getDrawingCache();
salezica
  • 74,081
  • 25
  • 105
  • 166
  • You mean that I cannot capture objects that are under on-screen keyboard? In that case, what you mean when saying external aid? Also, I don't need to capture keyboard, just anything, that is on my window, even if it is under something. – cheshie Feb 08 '13 at 19:44
  • can't say now, but seems that I cannot find that method. is it View's method? – cheshie Feb 08 '13 at 21:25
  • My bad: `DrawingCache`. Will edit and give you an example to try. Sorry I don't do it myself, but I don't have an Android dev setup here. – salezica Feb 09 '13 at 05:18
  • now screenshot is trimmed. I'm testing on a galaxy tab 2, with my code, I was getting an image 1024x600 with a blank part, where is on-screen keyboard and now I'm getting an 1024x173 image. So, result is the same, I cannot get object, that are placed under on-screen keyboard. – cheshie Feb 10 '13 at 06:15