I am developing a system application and I need to take a screenshot on the main screen.
In android 4.0 to 4.2 there is a hidden API in com.android.view.Surface that works fine by calling Surface.screenshot (width, height), it returns a screenshot bitmap:
public static Bitmap screenshot(int width, int height);
Starting with android 4.3, the screenshot () method has been moved to com.android.view.SurfaceControl. However, when I call SurfaceControl.screenshot (width, height) in the same way as in android 4.2, it returns null.
The application has permission READ_FRAME_BUFFER and is signed with a platform certificate, and it has sharedUserId from "android.uid.system". It works fine in 4.0 and 4.2, but returns null in 4.4, no warnings or errors in logcat.
In android 4.0 to 4.2, the Surface class is not hidden, just the screenshot () method is hidden. In Android 4.4, the SurfaceControl class is hidden.
So how can I make it work in android 4.4?
source
share