2

I'm developing an secure application where i'm restricting another application to record the moment of my application (like videos).

The think is i had restricted the screen capture (both screenshot and video recording) of my application as stated here, but i cant able to restrict the audio of my application's video.

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    setContentView(R.layout.activity_main);
    playVideo();
    //callAPI();
}

After screen capturing i can't able to see the video (shows black screen) but i can hear the audio.

Please help me to get out of this.

Thanks in advance

1 Answers1

0

you must detect first that a recording is started

you can achieve this by register display listener


 val displayManager = getSystemService(Context.DISPLAY_SERVICE) as? DisplayManager
        displayManager?.registerDisplayListener(listener, null)
       

    val listener = object : DisplayManager.DisplayListener {
        override fun onDisplayChanged(displayId: Int) {
            
        }

        override fun onDisplayAdded(displayId: Int) {
            
            // here stop video player 
        }

        override fun onDisplayRemoved(displayId: Int) {
          
        }
    }

FLAG_SECURE will make screen recording record a blank screen

Hint: this way only work if recording starts while activity is in foreground

UPDATE 1

The next workaround will work with most of third party recording apps before android 10:

by using AudioManager to mute mic, as these apps use mic

Mahmoud Mabrok
  • 1,362
  • 16
  • 24