The Privacy Screen plugin provides functionality to prevent sensitive information from being visible in app switchers and when leaving an app.
https://github.com/ionic-team/capacitor-privacy-screen.git
The Privacy Screen plugin provides functionality to prevent sensitive information from being visible in app switchers and when leaving an app.
Note: This plugin is supported on Android and iOS platforms only. It is not available for web platforms.
npm install @capacitor/privacy-screen
npx cap sync
FLAG_SECURE flag to the window. This provides comprehensive content protection:
dimBackground (shows a dim overlay) or shows the splash screen by default.privacyModeOnActivityHidden for scenarios like biometric promptsimport { PrivacyScreen } from '@capacitor/privacy-screen';
// Enable privacy screen with default settings
await PrivacyScreen.enable();
// Enable with platform-specific configuration
await PrivacyScreen.enable({
android: {
dimBackground: true,
privacyModeOnActivityHidden: 'splash'
},
ios: {
blurEffect: 'dark'
}
});
// Disable privacy screen
await PrivacyScreen.disable();
// Check if privacy screen is enabled
const { enabled } = await PrivacyScreen.isEnabled();
You can enable and disable the privacy screen on specific screens by calling enable() when entering a screen and disable() when leaving. Note: Make sure to call the appropriate method whenever navigating between screens, including when using back navigation.
import { PrivacyScreen } from '@capacitor/privacy-screen';
// Enable privacy screen when navigating to a secure screen
async function navigateToSecureScreen() {
await PrivacyScreen.enable({
android: { dimBackground: true },
ios: { blurEffect: 'dark' }
});
// Navigate to your secure screen
}
// Disable when navigating to a non-secure screen
async function navigateToPublicScreen() {
await PrivacyScreen.disable();
// Navigate to your public screen
}
enable(config?: PrivacyScreenConfig | undefined) => Promise<{ success: boolean; }>
Enable privacy screen protection
| Param | Type | Description |
|---|---|---|
config | PrivacyScreenConfig | Optional configuration for platform-specific behavior |
Promise<{ success: boolean; }>
disable() => Promise<{ success: boolean; }>
Disable privacy screen protection
Returns: Promise<{ success: boolean; }>
isEnabled() => Promise<{ enabled: boolean; }>
Check if privacy screen is currently enabled
Returns: Promise<{ enabled: boolean; }>
| Prop | Type | ||
|---|---|---|---|
android | { dimBackground?: boolean; preventScreenshots?: boolean; privacyModeOnActivityHidden?: 'none' \ | 'dim' \ | 'splash'; } |
ios | { blurEffect?: 'none' \ | 'light' \ | 'dark'; } |