4

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?

fadden
  • 51,356
  • 5
  • 116
  • 166
User0101
  • 95
  • 2
  • 6

2 Answers2

6

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().

fadden
  • 51,356
  • 5
  • 116
  • 166
  • Do you know whether it's also possible with other Views besides SurfaceView? Moreover I've tested it with the WindowManager which you also can set a secure-flag but the problem is that when I playback the video the view in the WindowManager is a "black-background", but I want the view should not appear entirely in the recorded video. – User0101 Apr 10 '16 at 11:23
  • All of the Views are drawn on a single layer, by the app itself. The SurfaceView's Surface is an independent layer that is handled by the system graphics compositor (SurfaceFlinger). The "secure" flag applies to an entire layer, which is why you can hide the Surface, but you can't hide individual Views. If you create a Presentation you can put whatever Views you want on it; this may be more useful to you than mirroring the display. (The test linked in my answer creates a Presentation and puts a single ImageView on it.) – fadden Apr 10 '16 at 16:15
  • The thing is that I want to recording outside my main-application, thus the user can do things in the home screen or in other apps. In addition I want to give him an floating overlay control panel which he can interact with (stop/pause recording). But this overlay panel shouldn't appear in the recording but rather only to the user. I managed to do so with the WindowManager and set it to secure but it's still appears in the video as a blanked view. I now trying to figure out how to make this transparent or invisble instead of a blanked view. – User0101 Apr 10 '16 at 18:17
  • 2
    I see... so you want full device recording, but with secure layers treated as invisible rather than black. I don't know of a way to do that. You'd probably need to define a "layer stack" within SurfaceFlinger than omitted the unwanted layers... I think it always blacks out secure layers on insecure displays (https://android.googlesource.com/platform/frameworks/native/+/marshmallow-mr1-release/services/surfaceflinger/Layer.cpp#663). – fadden Apr 10 '16 at 20:57
  • 3
    were you ever able to find a solution to this Azrael? – BionicSheep Oct 01 '16 at 21:16
  • Ping. Is it in any way possible? – omerjerk Oct 26 '16 at 06:50
  • @Azrael, you already found a solution to this? if yes, could share in some place please? –  Sep 22 '18 at 18:30
  • "Because you're creating a display for your own content, the user permission dialog is not shown." - @fadden Do you mean we can record the App's own screen without permission? May I know how we get MediaProjection instance in that case? – Ayyappa Jan 26 '20 at 13:56
0

You can use EZ filter to record particular layout.

Elangovan S
  • 192
  • 1
  • 1
  • 12