Detect screenshot attempts on Android 4.0+

2019-06-18 02:17发布

问题:

I am developing an Android application that places a high priority on protecting the user's data, to the point of storing nothing in persistent memory on the local device.

To further protect user data, we want to make a web-service call to our server whenever someone attempts to take a screenshot of the active application.

Solutions that I have seen so far include this snippet intended to prevent the screenshot from being taken and throwing a screenshot failure message in a Toast at the user. Another approach I was considering was listening for the combination of Volume Down and Power button that some devices use to take screenshots (though devices such as the Samsung S4 deviate from this method). My last resort was going to use a FileObserver in the location of the screenshot Gallery for changes while the app is running, but that also seems like a sub-optimal solution and introduces a Permission request that I'd rather not have. I also can't be sure of the file destination for the images.

I believe the Snapchat app is able to alert participants when a remote user attempts to take a screenshot. Do you have any suggestions on how this feature might be implemented, short of rooting the device? Non-official methods are welcome as well.

回答1:

FLAG_SECURE is probably the best way to avoid screenshots in a window, but as some commenters say here it has some workarounds.

Maybe this answer solves the question about how do they do it in Snapchat to detect when a screenshot has been taken.