2

i searched about the screenshot prevention. i found a answer but it blocks the screenshot for all activities in a app. but i need to block screenshots for specific activity.

Referring the below answer couldn't helped.

How do I prevent Android taking a screenshot when my app goes to the background?

Community
  • 1
  • 1
user3546693
  • 364
  • 3
  • 18
  • I don't see how the accepted answer to the question you linked to doesn't answer your question. In what way was it unclear? – Michael Nov 17 '15 at 06:57

1 Answers1

3

Use below code in onCreate() of your Activity:

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

setContentView(R.layout.main);

above code work for particular activity also.If you do not work this code then other problem there may be import of layout param wrong or place of code wrong.

Be careful about using WindowManager.LayoutParams.FLAG_SECURE, on some devices, this will make the view scrambled. Looks like a Samsung specific bug. I recommend the following:

if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
phoenix
  • 7,988
  • 6
  • 39
  • 45
Ketan Patel
  • 2,155
  • 19
  • 27