How to block taking screenshot for android app

882 views Asked by At

I am working on an android app where my requirement is to disable the screenshot functionality for the entire app

MainActivity.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                WindowManager.LayoutParams.FLAG_SECURE);
    }

I have used the above code to block the screenshot, partially it is working fine. As my code contains WebView to show the epub3(HTML + CSS + JS) contents on an app it is not specifically restricting that content only, it is allowing taking a screenshot for that content

please help thank you in advance.

2

There are 2 answers

2
CommonsWare On BEST ANSWER

for this we are using different activity

Then you are going to need to add FLAG_SECURE to that activity's window as well, as well as any other activity that you wish to secure. FLAG_SECURE works on a per-window basis, and each activity gets its own window.

0
Mr_vmh On

Add each activity on below onCreate()

 this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);