1

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

TuanPM
  • 685
  • 8
  • 29

1 Answers1

0

I can not resolve your problem with SurfaceControl.

But you can try follow example to capture the layer you want

https://github.com/nitiwari-dev/Blur-behind-alert-dialog

enter image description here

thuc do van
  • 131
  • 1
  • 7
  • Thanks for your suggestion, but the example you mentioned above can not solve my problem. I need to capture multiple activities in a screenshot, not just one. – TuanPM Jun 12 '20 at 02:42