I face a black screen whenever I use Windowmanager.LayoutParams.FLAG_SECURE to prevent screenshot and screen recordings on a device. This bug happens in specific devices like Google Pixel 6, Oppo, and Vivo.
The following app activates Windowmanager.LayoutParams.FLAG_SECURE on clicking a button and then screen turns black. The code is below: -
App.js: -
/* eslint-disable react/react-in-jsx-scope */
import {Button, StyleSheet, View} from ‘react-native’;
import * as ScreenCapture from ‘expo-screen-capture’;
export default function ScreenCaptureExample() {
const activate = async () => {
await ScreenCapture.preventScreenCaptureAsync();
};
const deactivate = async () => {
await ScreenCapture.allowScreenCaptureAsync();
};
return (
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: ‘center’,
justifyContent: ‘center’,
},
});
ScreenCaptureAndroid.js: -
import * as ScreenCapture from ‘expo-screen-capture’;
const allowScreenCapture = async () => {
try {
await ScreenCapture.allowScreenCaptureAsync();
} catch (e) {}
};
const disableScreenCapture = async () => {
try {
await ScreenCapture.preventScreenCaptureAsync();
} catch (e) {}
};
const func = {
allowScreenCapture,
disableScreenCapture,
};
export default func;
ScreenCaptureModule.kt (File from expo-screen-capture node_modules folder): -