AndroidUtilCode icon indicating copy to clipboard operation
AndroidUtilCode copied to clipboard

Toggling FLAG_SECURE in WindowManager to prevent taking screenshots

Open XiXiongMaoXiong opened this issue 4 years ago • 2 comments

Describe the feature

Toggle FLAG_SECURE to prevent screenshot form activity/class/base/app.

The FLAG_SECURE "flag" in WindowManager prevents taking a screenshot from the app's screen in Android versions above 7, and scrambles the snapped shot final image in Android versions lower than 7.

https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_SECURE

Reference

You can achieve it with only one line of code (Java): getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); Kotlin: window.setFlags( WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)

And to disable it (Java): getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); Kotlin: window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)

XiXiongMaoXiong avatar Nov 16 '21 13:11 XiXiongMaoXiong

@Blankj I hope you bother your lazy fucking bum and take a look at this cause you aren't merging shit since the last 10 months

XiXiongMaoXiong avatar Nov 16 '21 13:11 XiXiongMaoXiong

@XiXiongMaoXiong Almost 2 years lol

nicolasmanurung avatar Dec 30 '23 15:12 nicolasmanurung