5

I know that there are a lot of questions about capturing screenshots, and I have checked most of them. They have the same answer (with small code variations).

I have following method for screenshot capturing:

@NonNull
public static Bitmap takeScreenShot(Window window) throws IOException {
    final View rootView = window.getDecorView().getRootView();
    final boolean drawingCacheEnabled = rootView.isDrawingCacheEnabled();
    rootView.setDrawingCacheEnabled(true);

    try {
        return Bitmap.createBitmap(rootView.getDrawingCache());
    } finally {
        rootView.setDrawingCacheEnabled(drawingCacheEnabled);
    }
}

And you can use it like these: takeScreenShot(getActivity().getWindow())

However these approach has several limitations:

  1. If you have some dialogs on the screen they will not be captured on screenshot.
  2. Will it work with hardware accelerated views? According to documentation:

    When hardware acceleration is turned on, enabling the
    drawing cache has no effect on rendering because the system uses a
    different mechanism for acceleration which ignores the flag

  3. Screenshot contains black boxes instead of GLviews. (e.g. when you app has maps.). It seems to be as a result of 2nd point.

So my question is, is there any solution without rooting that can solve at least some of my issues?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Rostyslav Roshak
  • 3,859
  • 2
  • 35
  • 56

1 Answers1

1

Check out the following GitHub repo (not mine!): https://github.com/AndroidDeveloperLB/ScreenshotSample

Also, the following will be useful reading: How to properly take a screenshot, globally?

Richard
  • 948
  • 2
  • 11
  • 16