Privacy Screen
@capacitor-community/privacy-screen
Capacitor Privacy Screen Plugin
Introduction
⚡️ Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.
On Android, this plugin sets the FLAG_SECURE flag to treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.
On iOS, this plugin hides the webview window when the app is no longer active and loses focus (UIApplicationWillResignActiveNotification) so that a gray screen is shown instead.
Maintainers
Installation
npm install @capacitor-community/privacy-screen
npx cap sync
On iOS, no further steps are needed.
On Android, register the plugin in your main activity:
import com.getcapacitor.plugin.privacyscreen.PrivacyScreen;
public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.init(
savedInstanceState,
new ArrayList<Class<? extends Plugin>>() {
{
add(PrivacyScreen.class);
}
}
);
}
}
Configuration
No configuration required for this plugin.
Usage
The plugin only needs to be installed.
The protection is enabled by default.
However, you have the option to enable/disable the protection:
import { Plugins } from '@capacitor/core';
import '@capacitor-community/privacy-screen';
const enable = async () => {
await Plugins.PrivacyScreen.enable();
};
const disable = async () => {
await Plugins.PrivacyScreen.disable();
};
Changelog
See CHANGELOG.md.