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
Use SECURE FLAG in the Activity. Secure Flag Prevents Screen Recording Capture etc.
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE);
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.