0

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?

Dhanshri
  • 752
  • 6
  • 19

2 Answers2

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);
yuyuvvall
  • 11
  • 1
  • I did the same. But on oxygen os, it is not restricting the screenshot. – Dhanshri Jan 06 '22 at 13:37
  • @Dhanshri: Test on other environments. If your screenshots are not blocked across multiple devices, then perhaps you have the `setFlags()` call in the wrong spot -- you pretty much need to call it at the very top of `onCreate()` of the activity. If your screenshots are blocked elsewhere but are not blocked on certain devices, that's bad, and I would be interested to know the specific device model(s) that are affected. – CommonsWare Jan 06 '22 at 14:30
  • @CommonsWare Yeah, I tested on different environments & I called it on very top of ```onCreate ()```. On OnePlus 6T I am able to take screenshot. On MI, Pixel, samsung, Poco, etc screenshots are restricted. – Dhanshri Jan 06 '22 at 14:37
  • That's very disappointing. I do not know if you have much in the way of options for working around that limitation, though. – CommonsWare Jan 06 '22 at 15:37
  • Hi @CommonsWare , is there any way to disable screenshot/video recording in fragment? i had tried in activity and it works fine. But not in fragment. Do you have any idea on this? – S S Mar 24 '22 at 09:17
  • @ShanuS: We can only disable screen recording in a window. Activities have their own window. Dialogs have their own window. Ordinary fragments do not. `DialogFragments` have their own window, since they really create dialogs. So, perhaps you can switch to `DialogFragment` or otherwise arrange to have your `Fragment` have its own window. – CommonsWare Mar 24 '22 at 11:38
0

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)

Dhanshri
  • 752
  • 6
  • 19