Piyush Jiwane
Piyush Jiwane

Reputation: 179

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.

Upvotes: 0

Views: 1329

Answers (2)

Mr_vmh
Mr_vmh

Reputation: 167

Add each activity on below onCreate()

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

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1007544

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.

Upvotes: 1

Related Questions