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.
-
https://pub.dev/packages/flutter_windowmanager – Usama Altaf Feb 24 '21 at 12:49
-
The duplicate is wrong, because this question is an iOS question. The [android] tag likely confused people. If you want assistance debugging why your code doesn't work, you could post the code. – Ryan M Feb 25 '21 at 04:40
3 Answers
add line on MainActivity.java
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

- 71
- 7
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.

- 7,073
- 8
- 39
- 86
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.

- 7,073
- 8
- 39
- 86

- 2,044
- 2
- 19
- 34
-
-
The question is how to prevent the user from taking screenshots. #secure_application plugin will not fulfil this purpose. – Tapas Pal Feb 24 '21 at 13:13
-
@UsamaAltaf this answer, as well as the original question seems to just be a duplicate, you can flag this answer and the question as such – a_local_nobody Feb 24 '21 at 13:17