0

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?

Lino
  • 5,084
  • 3
  • 21
  • 39
user3698465
  • 185
  • 1
  • 10

1 Answers1

-1

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);
Venus
  • 453
  • 2
  • 9
  • 1
    Welcome back to Stack Overflow. It looks like it's been a while since you've posted and may not be aware of the current policies since most or all 6 of recent answers appear likely to have been entirely or partially written by AI (e.g., ChatGPT). Please be aware that [posting of AI-generated content is banned here](//meta.stackoverflow.com/q/421831). If you used an AI tool to assist with any answer, I would encourage you to delete it. Thanks! – NotTheDr01ds Jun 19 '23 at 16:36
  • 1
    **Readers should review this answer carefully and critically, as AI-generated information often contains fundamental errors and misinformation.** If you observe quality issues and/or have reason to believe that this answer was generated by AI, please leave feedback accordingly. The moderation team can use your help to identify quality issues. – NotTheDr01ds Jun 19 '23 at 16:36
  • The much higher answer rate and the verboseness suggest this has been generated by [ChatGPT_](https://meta.stackoverflow.com/questions/421831/temporary-policy-chatgpt-is-banned). – Peter Mortensen Jun 20 '23 at 16:36
  • 1
    This answer looks like it was generated by an AI (like ChatGPT), not by an actual human being. You should be aware that [posting AI-generated output is officially **BANNED** on Stack Overflow](https://meta.stackoverflow.com/q/421831). If this answer was indeed generated by an AI, then I strongly suggest you delete it before you get yourself into even bigger trouble: **WE TAKE PLAGIARISM SERIOUSLY HERE.** Please read: [Why posting GPT and ChatGPT generated answers is not currently allowed](https://stackoverflow.com/help/gpt-policy). – tchrist Jul 11 '23 at 13:25