Detect screenshot with Ionic

Is there any way to detect when a user does a screenshot for Android and iOS? There is a cordova plugin for iOS (https://github.com/Restocks/cordova-plugin-detect-screenshot) only but I don’t know if it will work with Ionic.

Thanks in advance

It will. You just have to find out how to listen to a global event.
http://ionicframework.com/docs/api/util/Events/ might be enough.

1 Like

@Copano

Did you get any luck with implementing this?

Tried both approaches but none of the is firing:

Approach 1:

import { Events } from 'ionic-angular';
...
this.events.subscribe("screenshot", () => {
    console.log("screenshot");
});

Approach 2:

declare let window;
...
window.addEventListener("screenshot", function() {
    console.log("screenshot");
}, false);

In the case other viewer is getting problem detecting screenshot, here’s what works for me:

document.addEventListener('screenshot', function() {
    console.log('screenshot');
}, false);