@capacitor-community/privacy-screen
Capacitor Privacy Screen Plugin
⚡️ 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. It also prevents screenshots (a black screen will be captured).
Disabling screenshots can interfere with plugins that hide the WebView like the Camera plugin. To avoid issues call disable
before using a plugin and then enable
after you are finished.
Maintainer | GitHub | Social |
---|---|---|
Robin Genz | robingenz | @robin_genz |
npm install @capacitor-community/privacy-screen
npx cap sync
boolean
| Configure whether the plugin should be enabled from startup. Only available for Android and iOS. | true
|
| **`imageName`** | string
| Configure whether the plugin should display a custom image from assets instead of a default background gray for the privacy screen. Only available for iOS. | ""
|
### Examples
In `capacitor.config.json`:
```json
{
"plugins": {
"PrivacyScreen": {
"enable": true,
"imageName": "Splashscreen"
}
}
}
```
In `capacitor.config.ts`:
```ts
/// A working example can be found here: robingenz/capacitor-plugin-demo
The plugin only needs to be installed. The protection is enabled by default.
However, you have the option to enable/disable the protection:
import { PrivacyScreen } from '@capacitor-community/privacy-screen';
const enable = async () => {
await PrivacyScreen.enable();
};
const disable = async () => {
await PrivacyScreen.disable();
};
'screenRecordingStarted'
|
| **`listenerFunc`** | () => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 3.0.2
--------------------
### addListener('screenRecordingStopped', ...)
```typescript
addListener(eventName: 'screenRecordingStopped', listenerFunc: () => void) => Promise'screenRecordingStopped'
|
| **`listenerFunc`** | () => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 3.0.2
--------------------
### addListener('screenshotTaken', ...)
```typescript
addListener(eventName: 'screenshotTaken', listenerFunc: () => void) => Promise'screenshotTaken'
|
| **`listenerFunc`** | () => void
|
**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle
**Since:** 3.2.0
--------------------
### removeAllListeners()
```typescript
removeAllListeners() => Promise() => Promise<void>
|
See CHANGELOG.md.
See LICENSE.