🌐 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 in the background).
🌐 On Android, the screen capture callback works without additional permissions only for Android 14+. You don't need to request or check permissions for blocking screen capture or using the callback on Android 14+.
🌐 If you want to use the screen capture callback on Android 13 or lower, you need to add the READ_MEDIA_IMAGES permission to your AndroidManifest.xml file. You can use the android.permissions key in your app config. See Android permissions for more information.
import{ usePreventScreenCapture }from'expo-screen-capture';import{Text,View}from'react-native';exportdefaultfunctionScreenCaptureExample(){usePreventScreenCapture();return(<Viewstyle={{flex:1,alignItems:'center',justifyContent:'center'}}><Text>As long as this component is mounted, this screen is unrecordable!</Text></View>);}
import*asScreenCapturefrom'expo-screen-capture';import{ useEffect }from'react';import{Button,StyleSheet,View}from'react-native';exportdefaultfunctionuseScreenCaptureCallback(){// Only use this if you add the READ_MEDIA_IMAGES permission to your AndroidManifest.xmlconsthasPermissions=async()=>{const{ status }=awaitScreenCapture.requestPermissionsAsync();return status ==='granted';};useEffect(()=>{let subscription;constaddListenerAsync=async()=>{if(awaithasPermissions()){
subscription =ScreenCapture.addScreenshotListener(()=>{alert('Thanks for screenshotting my beautiful app 😊');});}else{console.error('Permissions needed to subscribe to screenshot events are missing!');}};addListenerAsync();return()=>{
subscription?.remove();};},[]);}