I'm developing a system app on Android Pie (Android 9). I need to capture screen but not whole screen, i just need to capture from layer 1 (for Wallpaper) to layer 2 (for Application).
I used SurfaceControl like this:
Rect crop = new Rect(0, 0, 1920, 1080);
int width = crop.width();
int height = crop.height();
Bitmap bitmap = SurfaceControl.screenshot(crop, width, height, 1, 2, false, 0);
// "1" is the lowest (bottom-most Z order) surface layer to include in the screenshot
// "2" is the highest (top-most Z order) surface layer to include in the screenshot
but the returned bitmap
was always a black image.
My application is system private app, it was placed in /system/priv-app
. In additional, i already added below permission in the AndroidManifest.xml
<uses-permission android:name="android.permission.READ_FRAME_BUFFER" />
<uses-permission android:name="android.permission.ACCESS_SURFACE_FLINGER" />
What wrong i did ? Are there another way to capture screen with selected layers