Capture android screenshots layers

116 views Asked by At

I am currently capturing the screen using media projection, on the screen running another application, now I want to add elements to a floating window and still capture only the layer below.

When using

layoutParams.flags = WindowManager.LayoutParams.FLAG_SECURE

the window part that I display is black, and cant see the layer below

Does any one know a way to capture the screen without my overlays?

1

There are 1 answers

4
Venus On

To capture the screen without your overlays, you need to make sure that your floating window is transparent. You can achieve this by setting the alpha value of your floating window to 0, which will make it completely transparent.

Here's an example of how to create a transparent floating window:

// Create the layout for the floating window

View floatingView = LayoutInflater.from(this).inflate(R.layout.floating_window_layout, null);

// Set the alpha value of the floating view to 0 to make it transparent
floatingView.setAlpha(0);

// Set up the layout parameters for the floating window
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
    WindowManager.LayoutParams.WRAP_CONTENT,
    WindowManager.LayoutParams.WRAP_CONTENT,
    WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
    PixelFormat.TRANSPARENT);

// Add the floating window to the window manager
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
windowManager.addView(floatingView, layoutParams);