Allow screenshots using FLAG_SECURE

Viewed 10001

With FLAG_SECURE, screen capture is not allowed. I would like my application to be able to capture the screen, but to be blured or hidden when it goes to the background.

Would you know any way to do this? Is it possible to do it with FLAG_SECURE?

I read this topic (Android : Unable to screenshot after using method FLAG_SECURE) but nobody have any valid answer for that.

The use of FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS exclude the app to appear on recents apps, but not sure if prevent the android system to take and store the status screenshoot.

Any suggestion Thanks

1 Answers

It is indeed possible.

public override fun onPause() {
    window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
    super.onPause()
}

public override fun onResume() {
    super.onResume()
    window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

This basically sets secure flags only when the app is thrown to background and clears flags on entering to foreground, so you will be able to make screenshots. I use this code in some abstract Activity.

Related