1

I try to disable screenshot in current fragment,and enable it to others,for disable i use

getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE) or getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE)
and for enable use
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);

But this nor work,working only in Samsung galaxy s5 and more, in Galaxy s3 working only after fragment come from background, in htc m8s it dont work never!!!

And it always work when i gove flag before my main Activity setContentView method,it work for all devices!I have only one Activity,and i want to disable screenShot only for one fragment!

JohnPaul
  • 714
  • 5
  • 14
Light
  • 11
  • 5
  • were you able to find out why you were seeing the different behaviour on certain devices? I'm seeing the same thing now (screenshot blocking works only after coming back from background), and I'm not able to figure out why. – Rohan Dhruva May 09 '17 at 21:24

1 Answers1

1

in your Activity, and before setContentView(), puth these lines of code:

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

setContentView(R.layout.main_activity);
Khalid Taha
  • 3,183
  • 5
  • 27
  • 43