how to capture a screenshot?

Viewed 191

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?

1 Answers
Related