July 30, 2026 — The unofficial Laracon US Day 3. Get your ticket to The Vibes
Plugin Marketplace
srwiez/nativephp-mobile-screenshots logo

srwiez/nativephp-mobile-screenshots

A NativePHP plugin for capturing screenshots on mobile devices

Screenshots for NativePHP Mobile#

Lock down sensitive screens. Catch capture attempts. Respond instantly.#

Screenshots plugin on iOS Screenshots plugin on Android

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 recordingsFLAG_SECURE on 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#

Copied!
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#

Copied!
use SRWieZ\NativePHP\Mobile\Screenshots\Facades\MobileScreenshots;
 
// Protect a sensitive screen
MobileScreenshots::block();
 
// Detect when users take screenshots
MobileScreenshots::startDetection();
 
// Capture the screen programmatically
$captureId = MobileScreenshots::capture();

API Reference#

Screenshot Detection#

Detect when users take screenshots of your app.

Copied!
// Start listening for screenshots
MobileScreenshots::startDetection();
 
// Stop listening
MobileScreenshots::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.

Copied!
// Block screenshots
MobileScreenshots::block();
 
// Allow screenshots again
MobileScreenshots::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.

Copied!
// Returns a capture ID to correlate with events
$captureId = MobileScreenshots::capture();

Screen Recording Detection iOS Only#

Detect and respond to screen recording attempts.

Copied!
// Check if currently being recorded
$result = MobileScreenshots::isRecording();
// Returns: ['recording' => true/false]
 
// Start listening for recording changes
MobileScreenshots::startRecordingDetection();
 
// Stop listening
MobileScreenshots::stopRecordingDetection();

Events#

Listen for native events using NativePHP's event system.

ScreenshotDetected#

Fired when the user takes a screenshot.

Copied!
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.

Copied!
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.

Copied!
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.

Copied!
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.

Copied!
use SRWieZ\NativePHP\Mobile\Screenshots\Events\ScreenRecordingStopped;
 
#[OnNative(ScreenRecordingStopped::class)]
public function handleRecordingStopped($timestamp = null)
{
// User stopped screen recording
}

JavaScript API#

Copied!
import { mobileScreenshots } from '@srwiez/nativephp-mobile-screenshots';
 
// Detection
await mobileScreenshots.startDetection();
await mobileScreenshots.stopDetection();
 
// Blocking
await mobileScreenshots.block();
await mobileScreenshots.allow();
const { blocked } = await mobileScreenshots.isBlocked();
 
// Capture
const { 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; use block() 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
Copied!
// For maximum protection on both platforms:
 
// 1. Always block when showing sensitive content
MobileScreenshots::block();
 
// 2. Start detection to log/audit attempts
MobileScreenshots::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 to ContentObserver on older versions)
  • Android 13+ (API 33): READ_MEDIA_IMAGES permission for screenshot path detection
  • Android 10+ (API 29): MediaStore scoped storage for screenshot path

Support#

Bugs, questions, and feature requests should be reported at github.com/SRWieZ/nativephp-mobile-packages.