Search code examples
androidandroid-mediaprojection

Android record screen but only specific 'layers'/views


I use the MediaProjection API to record a screen in Android. Now I want to know whether it's possible to create a let's say "hidden" view which you actually can see but not in the video thus the view shouldn't be recorded. Furthermore is it possible to disable the recording of notifications or even the notification-center?

So is it possible to configure like a 'surface-layer-system', thus you can decide which layer you want to record?


Solution

  • Preventing a layer from appearing in recordings can be done by setting the "secure" flag. See for example the "multi-surface test" in Grafika, which sets the flag on one of its SurfaceViews.

    You will configure a virtual display to only show your app's own windows if you use createVirtualDisplay() directly, rather than going through MediaProjectionManager. Because you're creating a display for your own content, the user permission dialog is not shown. See for example the tests for DisplayManager#createVirtualDisplay().