Home » Android » How to prevent Screen Capture in Android

How to prevent Screen Capture in Android

Posted by: admin February 23, 2018 Leave a comment


Is it possible to prevent the screen recording in Android Application?

I would like to develop an Android Secure Application. In that I need to detect screen recording software which are running background and kill them. I have used SECURE FLAG for prevent screenshots. But I dont know is it possible to prevent Video capturing of Android Screen also. Let me know how to prevent screen capturing (video / screenshots).


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.

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.

2) 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.


It seems that you know how to disable screenshots from your app and there are other answers helping you on that. But I will try to give you some important information that no one is giving you.

1) You can not have an app which is 100% secure from taking screenshots (photo/video). There is no official way to take screenshots in Android. If an app is recording screens, then it must be using some non-supported methods (either rooting or using the SDK).

There is very little scope for you to block an app if it is using root access to record screens.

2) No one mentioned this issue here, but be very careful while using WindowManager.LayoutParams.FLAG_SECURE. It has been verified in many devices (like on Samsung Galaxy ACE, e.g. GT-S5830), that this makes the entire view scrambled. Like this,

enter image description here

Please put a check like this,

if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

It works perfectly on ICS devices, so no problem there.

3) I also found out that even on newer devices like Android 4.3, this causes animation problems when the screen is rotated. Please check this bug report.


Try this:

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


Just add this line:

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

Before your setContentView() method.


You can make your app as device/profile owner and call setScreenCaptureDisabled(). From the docs, this api does the following:

public void setScreenCaptureDisabled (ComponentName admin, boolean disabled)
Added in API level 21

Called by a device/profile owner to set whether the screen capture is
disabled. Disabling screen capture also prevents the content from
being shown on display devices that do not have a secure video output.
See FLAG_SECURE for more details about secure surfaces and secure

The calling device admin must be a device or profile owner. If it is
not, a security exception will be thrown. Parameters admin Which
DeviceAdminReceiver this request is associated with. disabled Whether
screen capture is disabled or not.

Alternatively you can become an MDM(Mobile Device Management) partner app.OEMs provides additional APIs to their MDM partner apps to control the device.For example samsung provides api to control screen recording on the device to their MDM partners.

Currently this is the only way you can enforce screen capture restrictions.


To disable Screen Capture:

Add following line of code in onCreate() method:


To enable Screen Capture:

Find for LayoutParams.FLAG_SECURE and remove the line of code.


According to this official guide, you can add WindowManager.LayoutParams.FLAG_SECURE to your window layout and it will disallow screenshots.


about photo screenshot,
FLAG_SECURE not working rooted device.

but if you monitor the screenshot file, you can prevent from getting original file.

try this one.

1. monitoring screenshot(file monitor) with android remote service

2. delete original screenshot image.

3. deliver the bitmap instance so you can modify.