Expo

Get Started
API Reference

ScreenCapture

expo-screen-capture allows you to protect screens in your app from being captured or recorded, as well as be notified if a screenshot is taken while your app is foregrounded. The two most common reasons you may want to prevent screen capture are:
  • If a screen is displaying sensitive information (password, credit card data, etc.)
  • You are displaying paid content that you don't want recorded and shared
This is especially important on Android, since the android.media.projection API allows third-party apps to perform screen capture or screen sharing (even if the app is backgrounded).
Currently, taking screenshots on iOS cannot be prevented. This is due to underlying OS limitations.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

Installation

expo install expo-screen-capture

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

import { usePreventScreenCapture } from 'expo-screen-capture';
import React from 'react';
import { Text, View } from 'react-native';

export default function ScreenCaptureExample {
  usePreventScreenCapture();
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>This is an unrecordable screen!</Text>
    </View>
  );
}

import * as ScreenCapture from 'expo-screen-capture';
import React from 'react';
import { Button, View } from 'react-native';

export default class ScreenCaptureExample extends React.Component {
  componentDidMount() {
    ScreenCapture.addScreenshotListener(() => {
      alert('Thanks for screenshotting my beautiful app 😊');
    }); 
  }

  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Button onPress={this._activate}>Activate</Button>
        <Button onPress={this._deactivate}>Deactivate</Button>
      </View>
    );
  }

  _activate = async () => {
    await ScreenCapture.preventScreenCaptureAsync(); 
  };

  _deactivate = async () => {
    await ScreenCapture.allowScreenCaptureAsync(); 
  };
}

import * as ScreenCapture from 'expo-screen-capture';

Methods

A React hook to prevent screen capturing for as long as the owner component is mounted.

  • key (string) [Optional] If provided, this will prevent multiple instances of this hook or the preventScreenCaptureAsync and allowScreenCaptureAsync methods from conflicting with each other. This argument is useful if you have multiple active components using the allowScreenCaptureAsync hook. Defaults to default.

Prevents screenshots and screen recordings until allowScreenCaptureAsync is called. If you are already preventing screen capture, this method does nothing (unless you pass a new and unique key).
Please note that on iOS, this will only prevent screen recordings, and is only available on iOS 11 and newer. On older iOS versions, this method does nothing.

  • key (string) [Optional] If provided, this will help prevent multiple instances of the preventScreenCaptureAsync and allowScreenCaptureAsync methods (and usePreventScreenCapture hook) from conflicting with each other. When using multiple keys, you'll have to re-allow each one in order to re-enable screen capturing. Defaults to default.

Re-allows the user to screen record or screenshot your app. If you haven't called preventScreenCaptureAsync() yet, this method does nothing

  • key (string) [Optional] The value must be the same as the key passed to preventScreenCaptureAsync in order to re-enable screen capturing.

Adds a listener that will fire whenever the user takes a screenshot while the app is foregrounded. On Android, this method requires the READ_EXTERNAL_STORAGE permission- you can request this with Permissions.askAsync(Permissions.CAMERA_ROLL).

  • listener (function) The function that will be executed when the user takes a screenshot. This function accepts no arguments.

A Subscription object that you can use to unregister the listener, either by calling .remove() or passing it to removeScreenshotListener.

Removes the subscription you provide, so that you are no longer listening for screen shots.

  • subscription (Subscription) Subscription returned by addScreenshotListener. If you prefer, you can also call .remove on that Subscription object, e.g.
let mySubscription = addScreenshotListener(() => {
  console.log("You took a screenshot!");
})
...
mySubscription.remove();
// OR
removeScreenshotListener(mySubscription);