'Disable screenshot in Android application

I want to disable screenshot but in some versions it is not working.

I have called registerActivityLifecycleCallback(this) in onCreate() method.

Is screenshot disable functionality varies with different versions of Android? Anyone have any idea about this?



Solution 1:[1]

I'm going to say that it is not possible to completely prevent screen/video capture of any android app through supported means. But if you only want to block it for normal android devices, the SECURE FLAG is substantial.

  1. The secure flag does block both normal screenshot and video capture.
  1. Also documentation at this link says that

    Window flag: treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.

    Above solution will surely prevent applications from capturing Video of your app

See the answer here.

  1. There are alternative means of capturing screen content.

It may be possible to capture the screen of another app on a rooted device or through using the SDK,

which both offer little to no chance of you either blocking it or receiving notification of it.

For example: there exists software to mirror your phone screen to your computer via the SDK and so screen capture software could be used there, undiscoverable by your app.

See the answer here.

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

Solution 2:[2]

As per analysis, restrictions of screenshot below code will work but it will not work on Oxygen Os version 9, because they made OS like that user can take screenshots. It is also mentioned on OnePlus forum.

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 yuyuvvall
Solution 2 Dhanshri