Implementing screenshot protection in mobile applications
Banking app shows balance, account number, transaction details — all can be on screenshot in gallery, read by another app or leak via cloud backup. On iOS screenshot automatically saves to Photos. On Android apps with necessary permissions can read MediaStore. Screenshot protection — standard requirement in fintech and medical apps.
Android: FLAG_SECURE
One line that works:
window.setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE)
FLAG_SECURE does two things: forbids system tools from creating window screenshot (screenshot button doesn't work, returns blank screen) and marks surface as protected — other apps can't capture contents via MediaProjection.
Best place — onCreate Activity before setContentView. For Fragment-based app on single Activity — applies to whole app at once.
Nuance: FLAG_SECURE works for system API screenshots. Physical camera shooting screen — nothing blocks it programmatically.
iOS: UIScreen and WindowScene
iOS has no direct FLAG_SECURE equivalent. Standard approach — react to screenshot, not block it.
Screenshot detection:
NotificationCenter.default.addObserver(
forName: UIApplication.userDidTakeScreenshotNotification,
object: nil,
queue: .main
) { _ in
// log, show warning, invalidate session
}
Content blocking on screenshot. Screenshot created by system before notification reaches app — can't block after fact. Alternative: subscribe to UIScreen.capturedDidChangeNotification (triggers when screen capture begins, including AirPlay mirroring and QuickTime) and hide sensitive content proactively.
NotificationCenter.default.addObserver(
forName: UIScreen.capturedDidChangeNotification,
object: nil,
queue: .main
) { [weak self] _ in
self?.sensitiveView.isHidden = UIScreen.main.isCaptured
}
Works for screen recording and mirroring, but not screenshot button click — isCaptured doesn't become true on single shot.
Keychain and SecureTextField trick. For text fields with sensitive data — isSecureTextEntry = true. iOS automatically blurs such field contents on screenshots by Passbook/Notes system app and in task switcher.
Overlay approach. On background (sceneWillResignActive) show UIWindow with placeholder over app:
func sceneWillResignActive(_ scene: UIScene) {
privacyWindow?.isHidden = false
}
func sceneDidBecomeActive(_ scene: UIScene) {
privacyWindow?.isHidden = true
}
Protects preview in App Switcher — standard practice for fintech apps.
React Native and Flutter
React Native: react-native-flag-secure-android for Android, custom native module for iOS. For Flutter — flutter_windowmanager package on Android, native platform channel for iOS overlay.
Timeline for implementation: Android FLAG_SECURE + iOS overlay on background + reaction to capturedDidChangeNotification — about 1 day with testing on both platforms.







