I ran this example: https://github.com/android/media-samples/tree/main/ScreenCapture
And changed the display to be public so that I can access it using scrcpy:
mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture",
mSurfaceView.getWidth(), mSurfaceView.getHeight(), mScreenDensity,
DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC,
mSurface, null, null);
When I open the display using scrcpy, I get a completely black screen, while on the preview it's showing correctly.
Why is it giving a black screen through scrcpy?
I'm assuming it's because the display is not secure (the warning "WARN: Display doesn't have FLAG_SUPPORTS_PROTECTED_BUFFERS flag, mirroring can be restricted"), but there is no way for a regular app to create a secure virtual display, since the permission is for system apps only.
Any way to get it working?