how to prevent screenshot and screen recording in flutter app

Viewed 1913

I want to prevent user from taking screenshots and screenrecording,I try to add native code for both android and ios,for android it perfectly work but for ios it not working.

3 Answers

add line on MainActivity.java

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

In Flutter there is no such public API that will allow you to prevent from taking screenshots and the reason you have already mentioned in your question that native Android works perfectly but native iOS doesn't because iOS doesn't provide any such public API that can restrict users to take screenshots.

Although there is a way that can notify you that a screenshot has taken. You can take a look at UIApplicationUserDidTakeScreenshotNotification but notification will be posted AFTER the screenshot is taken.

The simplest way to do this is to use a flutter package called flutter_windowmanager

Future<void> secureScreen() async {
await FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE); 
}

@override
 void initState() {
 secureScreen();
 super.initState();
}

If you want to make your whole app screenshot disable just call securescreen() method (defined above) inside your main() function in main.dart file.

Note: As flutter_windowmanager only wraps and exposes an underlying Android-specific interface, there is no iOS support planned or possible. For those interested in cross-platform FLAG_SECURE functionality, this functionality has been re-created in the third-party secure_application plugin.

Related