How to take a screenshot?

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

I have the following screen capture method:

@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 this: takeScreenShot(getActivity().getWindow())

However, this approach has several limitations:

  • If you have some dialogs on the screen, they will not be a screenshot.
  • Will it work with hardware accelerated views? In accordance with the documentation:

    When hardware acceleration is enabled, enabling cache drawing does not affect rendering because the system uses a different acceleration mechanism that ignores the flag

  • The screenshot contains black boxes instead of GLviews. (for example, when the application has maps.). This seems to be the result of point 2.

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

+5
source share
1 answer

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

The following will also be useful: How to take a screenshot all over the world?

+1
source

Source: https://habr.com/ru/post/1273459/


All Articles