Screenshots for NativePHP Mobile#
Lock down sensitive screens. Catch capture attempts. Respond instantly.#
The privacy layer your mobile app was missing. Block screenshots and screen recordings on screens showing account balances, medical records, exam questions or premium content — and get a real-time event the moment a user tries to capture something they shouldn't.
Why this plugin?#
- 🔒 Block screenshots & screen recordings —
FLAG_SECUREon Android, privacy overlay on iOS. One line of PHP. - 🛎️ Detect every capture attempt — fire a Laravel event the instant a user screenshots or starts recording.
- 📸 Capture programmatically — grab the current screen from server code for bug reports, feedback, or audit trails.
- 📱 Battle-tested on both platforms — iOS 17+ and Android 8+ with platform-native implementations.
Features at a glance#
| Feature | Android | iOS |
|---|---|---|
| Programmatic screenshot capture | ✅ | ✅ |
| Screenshot detection | ✅ | ✅ |
| Screenshot blocking | ✅ | ✅ privacy overlay |
| Screen recording detection | — | ✅ |
| Screen recording blocking | ✅ | ✅ privacy overlay |
Perfect for#
Banking & fintech · Healthcare portals · Exam proctoring · Enterprise document viewers · Premium video & streaming · Legal & confidential communications
Installation#
composer require srwiez/nativephp-mobile-screenshots php artisan vendor:publish --tag=nativephp-plugins-provider php artisan native:plugin:register srwiez/nativephp-mobile-screenshots
Quick Start#
use SRWieZ\NativePHP\Mobile\Screenshots\Facades\MobileScreenshots; // Protect a sensitive screenMobileScreenshots::block(); // Detect when users take screenshotsMobileScreenshots::startDetection(); // Capture the screen programmatically$captureId = MobileScreenshots::capture();
API Reference#
Screenshot Detection#
Detect when users take screenshots of your app.
// Start listening for screenshotsMobileScreenshots::startDetection(); // Stop listeningMobileScreenshots::stopDetection();
| Platform | Behavior |
|---|---|
| Android | Uses ScreenCaptureCallback (API 34+) with ContentObserver fallback. Returns screenshot path. |
| iOS | Uses userDidTakeScreenshotNotification. Path not available. |
Screenshot Blocking#
Prevent screenshots from being captured.
// Block screenshotsMobileScreenshots::block(); // Allow screenshots againMobileScreenshots::allow(); // Check current status$blocked = MobileScreenshots::isBlocked();
| Platform | Behavior |
|---|---|
| Android | Uses FLAG_SECURE - completely prevents screenshots and screen recordings. Screenshots appear black. |
| iOS | Uses privacy overlay technique. Shows "Screen recording is disabled" during screen capture. Best-effort approach. |
Caution
iOS Limitation: Apple does not provide any API to prevent screenshots. This plugin uses a privacy overlay as a best-effort workaround, but determined users may still capture content. For sensitive data on iOS, consider combining blocking with detection to log and respond to capture attempts.
Programmatic Screen Capture#
Capture the current screen from your app code.
// Returns a capture ID to correlate with events$captureId = MobileScreenshots::capture();
Screen Recording Detection iOS Only#
Detect and respond to screen recording attempts.
// Check if currently being recorded$result = MobileScreenshots::isRecording();// Returns: ['recording' => true/false] // Start listening for recording changesMobileScreenshots::startRecordingDetection(); // Stop listeningMobileScreenshots::stopRecordingDetection();
Events#
Listen for native events using NativePHP's event system.
ScreenshotDetected#
Fired when the user takes a screenshot.
use Native\Mobile\Attributes\OnNative;use SRWieZ\NativePHP\Mobile\Screenshots\Events\ScreenshotDetected; #[OnNative(ScreenshotDetected::class)]public function handleScreenshot($path = null, $timestamp = null){ // $path is only available on Android Log::warning('User took a screenshot', ['path' => $path]);}
ScreenshotCaptured#
Fired when programmatic capture completes successfully.
use SRWieZ\NativePHP\Mobile\Screenshots\Events\ScreenshotCaptured; #[OnNative(ScreenshotCaptured::class)]public function handleCaptured($path, $id = null, $success = true){ // Process the captured image at $path}
ScreenshotCaptureFailed#
Fired when programmatic capture fails.
use SRWieZ\NativePHP\Mobile\Screenshots\Events\ScreenshotCaptureFailed; #[OnNative(ScreenshotCaptureFailed::class)]public function handleFailed($error, $id = null){ Log::error('Screenshot capture failed', ['error' => $error]);}
ScreenRecordingStarted iOS Only#
Fired when screen recording begins.
use SRWieZ\NativePHP\Mobile\Screenshots\Events\ScreenRecordingStarted; #[OnNative(ScreenRecordingStarted::class)]public function handleRecordingStarted($timestamp = null){ // User started screen recording // Call MobileScreenshots::block() if you want to show a privacy screen}
ScreenRecordingStopped iOS Only#
Fired when screen recording ends.
use SRWieZ\NativePHP\Mobile\Screenshots\Events\ScreenRecordingStopped; #[OnNative(ScreenRecordingStopped::class)]public function handleRecordingStopped($timestamp = null){ // User stopped screen recording}
JavaScript API#
import { mobileScreenshots } from '@srwiez/nativephp-mobile-screenshots'; // Detectionawait mobileScreenshots.startDetection();await mobileScreenshots.stopDetection(); // Blockingawait mobileScreenshots.block();await mobileScreenshots.allow();const { blocked } = await mobileScreenshots.isBlocked(); // Captureconst { id } = await mobileScreenshots.capture(); // Recording detection (iOS)const { recording } = await mobileScreenshots.isRecording();await mobileScreenshots.startRecordingDetection();await mobileScreenshots.stopRecordingDetection();
Platform Comparison#
Android#
Android provides robust, system-level protection through FLAG_SECURE:
- Screenshots: Completely blocked - appear as black images
- Screen Recording: Completely blocked - shows black screen
- Screen Mirroring: Blocked
- Reliability: Very high - enforced at the window manager level
iOS#
iOS has more limited APIs, so this plugin uses creative workarounds:
- Screenshots: Cannot be prevented, but can be detected instantly
- Screen Recording: Can be detected via
UIScreen.isCaptured; useblock()to show privacy overlay - Privacy Overlay: A black screen with message appears during capture/recording attempts
- Reliability: Best-effort - determined users may still capture content
Recommended Strategy#
// For maximum protection on both platforms: // 1. Always block when showing sensitive contentMobileScreenshots::block(); // 2. Start detection to log/audit attemptsMobileScreenshots::startDetection(); // 3. On iOS, detect screen recording (fires events only)MobileScreenshots::startRecordingDetection(); // block() handles privacy screen during recording on iOS
Use Cases#
- Banking & Finance - Protect account balances, transaction history, card details
- Healthcare - Secure patient records, lab results, prescriptions
- Enterprise - Guard confidential documents, internal communications
- Education - Prevent cheating during online exams
- Media & Entertainment - Protect premium content from piracy
- Legal - Secure sensitive case documents and communications
Version Support#
| Platform | Minimum Version |
|---|---|
| Android | 8.0 (API 26) |
| iOS | 17.0 |
Features requiring higher versions:
- Android 14+ (API 34): Native screenshot detection via
ScreenCaptureCallback(falls back toContentObserveron older versions) - Android 13+ (API 33):
READ_MEDIA_IMAGESpermission for screenshot path detection - Android 10+ (API 29):
MediaStorescoped storage for screenshot path
Support#
Bugs, questions, and feature requests should be reported at github.com/SRWieZ/nativephp-mobile-packages.