Search code examples
androidandroid-webviewscreenshotepub3

How to block taking screenshot for android app


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.


Solution

  • 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.