Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow screenshots using FLAG_SECURE

With FLAG_SECURE, screen capture is not allowed. I would like my application to be able to capture the screen, but to be blured or hidden when it goes to the background.

Would you know any way to do this? Is it possible to do it with FLAG_SECURE?

I read this topic (Android : Unable to screenshot after using method FLAG_SECURE) but nobody have any valid answer for that.

The use of FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS exclude the app to appear on recents apps, but not sure if prevent the android system to take and store the status screenshoot.

Any suggestion Thanks

like image 439
A981K Avatar asked Sep 05 '18 13:09

A981K


People also ask

How do I give you permission to take screenshots?

On your Android phone or tablet, open the Settings app . Assist & voice input. Turn on Use screenshot.

How do I change security policy to allow screenshots?

Launch “Chrome.” Then enter “ chrome://flags ” without quotes into the address bar. On the Chrome flags screen, type “ Incognito Screenshot ” without quotes into the search box. The “Incognito Screenshot” option now appears in the results. Click on the pull-down menu underneath it, then select “Enabled.”

How do I disable screenshot blocking?

There is currently no way to disable this “feature”. You can install Firefox and take a screenshot in Incognito mode there, but if you are taking a screenshot in Google Chrome, you must not be using Incognito Mode to do it.


1 Answers

It is indeed possible.

public override fun onPause() {
    window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
    super.onPause()
}

public override fun onResume() {
    super.onResume()
    window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}

This basically sets secure flags only when the app is thrown to background and clears flags on entering to foreground, so you will be able to make screenshots. I use this code in some abstract Activity.

like image 61
Bio-Matic Avatar answered Sep 21 '22 19:09

Bio-Matic